0

Issue

In my project I a have a room table named 'content' with a Double attribute 'archivedCount'. In the latest version of the app the attribute archivedCount attribute is re-named to dismissCount, still as type Double.

Android API Level / SQL Version

28 / 3.19

Original Content model

@Entity(tableName = "content")
data class Content(@PrimaryKey var id: String, var archiveCount: Double) : Parcelable {...}

New Content model

@Entity(tableName = "content")
data class Content(@PrimaryKey var id: String, var dismissCount: Double) : Parcelable {...}

Runtime error

java.lang.IllegalStateException: Migration didn't properly handle content(app.coinverse.content.models.Content).

I've inspected the Expected and Found tables the log prints and they appear to be identical.

Attempted Solution

I attempted the complex schema change as outlined by a Google Developer Advocate unsuccessfully in order to modify the name of one attribute / column. Here is a basic version of what I attempted. 

val MIGRATION_1_2: Migration = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
    // Create the new table
    database.execSQL("CREATE TABLE content_new (id TEXT, dismissCount REAL, PRIMARY KEY(id))")
    // Copy the data
    database.execSQL("INSERT INTO content_new (id, dismissCount) SELECT id, archiveCount FROM content")
    // Remove the old table
    database.execSQL("DROP TABLE content")
    // Change the table name to the correct one
    database.execSQL("ALTER TABLE content_new RENAME TO content")
}

}

1 Answer 1

0

Can't see anything wrong with your implementation, I would suggest that you use a different @Entity class that is not named Content() and try again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.