在我的项目中,我有一个名为“ content ”的房间表,该房间表具有 Double 属性“ archivedCount ”。在该应用程序的最新版本中,属性 archivedCount 属性被重命名为 dismissCount ,仍为 Double。
28 / 3.19
@Entity(tableName = "content")
data class Content(@PrimaryKey var id: String, var archiveCount: Double) : Parcelable {...}
@Entity(tableName = "content")
data class Content(@PrimaryKey var id: String, var dismissCount: Double) : Parcelable {...}
java.lang.IllegalStateException: Migration didn't properly handle content(app.coinverse.content.models.Content).
我检查了日志打印的Expected and Found表,它们看起来是相同的。
我尝试使用Google Developer Advocate概述的complex schema change失败,以便修改一个属性/列的名称。这是我尝试过的基本版本。
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")
}
}
答案 0 :(得分:0)
看不到您的实现有什么问题,我建议您使用另一个未命名为Content()的@Entity类,然后重试。