Reputation: 218
I am trying to add a column to an existing table in the database. The column is type ArrayList<Date>
I wrote a migration step, increased database version number, and added the migration. When I run the migration (run the app), I get the error:
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter value
when attempting to read data from that table.
I have tried following the steps here: https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929
I have also tested with other data types, and it has migrated successfully. Seems like the issue is adding Lists or ArrayList
s.
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE product ADD COLUMN ingredients TEXT"
)
}
}
Upvotes: 0
Views: 382
Reputation: 39873
You're altering a table without setting a default value. Therefore the default is null for all rows already present within the table. Since you require the Kotlin property to be non-null, you receive the IllegalArgumentException
.
To resolve the issue, you'd have to alter the table to contain a default value for ingredients
and declare it non-null as well.
val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"ALTER TABLE product ADD COLUMN ingredients TEXT NOT NULL DEFAULT ''"
)
}
}
Alternatively you could make the ingredients
Kotlin property nullable.
Upvotes: 1