I was trying to implement a simple auto migration that just adds a nullable string field to my only table, but for some reason I am getting the following error in the autoMigrations = [AutoMigration(from = 1, to = 2)]
line:
Type mismatch: inferred type is AutoMigration but KClass<*> was expected
I say that this is a weird error, because even the documentation has it this way.
The full code is below:
@Database(
version = 2,
entities = [Note::class],
autoMigrations = [AutoMigration(from = 1, to = 2)]
)
@TypeConverters(Converters::class)
abstract class NotesDB : RoomDatabase() {
abstract fun noteDao(): NoteDao
companion object {
@Volatile
private var INSTANCE: NotesDB? = null
fun getDB(context: Context): NotesDB {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
NotesDB::class.java,
"notesDB"
).build()
INSTANCE = instance
instance
}
}
}
}
Change room version in your build.gradle to the newest one (2.4.0-alpha04 at the moment). Then if you will get an error about room.schemaLocation, look at this answer https://stackoverflow.com/a/44424908/6568162
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With