我的错误:
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for '[Singleton:'data.local.sqldelight.AppDatabase']
我会立即解释说,使用
它可以爆炸JdbcSqliteDriver.IN_MEMORY
我正在实施
DatabaseDriberFactory
:
actual class DatabaseDriverFactory {
actual fun createDriver(): SqlDriver {
val databasePath = File(System.getProperty("java.io.tmpdir"), "${DatabaseHelper.DATABASE_NAME}.db")
println(databasePath.path)
val driver = JdbcSqliteDriver(
url = "jdbc:sqlite:test.db",
properties = Properties().apply { put("foreign_keys", "true") }
).also {
AppDatabase.Schema.create(it)
}
return driver
}
}
Koin.kt
:
val databaseModule = module {
single {
createDatabase(driver = get())
}
single<ITeamDao> { TeamDao() }
}
稍后该模块将全部初始化
build.gradle.kts
:
sqldelight {
databases {
create("AppDatabase") {
packageName.set("data.local.sqldelight")
srcDirs.setFrom("src/commonMain/kotlin")
// project.set(listOf("kotlin"))
// schemaOutputDirectory = file("src/commonMain/sqldelight/schema")
}
}
}
我试图找到如何解决这个错误,但我找不到
我也收到以下错误:
Caused by: org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_FOREIGNKEY] A foreign key constraint failed (FOREIGN KEY constraint failed)
我遇到了两次这个问题,第一次是在创建数据库之前开始填充数据库时。还有第二个
generateAsync.set(true)