我现在使用Room而不是经典的sqlite语句,并且遇到以下问题。 当我打开“标签”表时,出现以下错误。
java.lang.IllegalStateException: Migration didn't properly handle tags(de.yochyo.ybooru.database.entities.Tag).
Expected:
TableInfo{name='tags', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, creation=Column{name='creation', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}, isFavorite=Column{name='isFavorite', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='tags', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, Date=Column{name='Date', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}, isFavorite=Column{name='isFavorite', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
at de.yochyo.ybooru.database.Database_Impl$1.validateMigration(Database_Impl.java:81)
at android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:87)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onUpgrade(FrameworkSQLiteOpenHelper.java:133)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:398)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:298)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
at android.arch.persistence.room.RoomDatabase.query(RoomDatabase.java:233)
at de.yochyo.ybooru.database.entities.TagDao_Impl.getAllTags(TagDao_Impl.java:142)
at de.yochyo.ybooru.database.Database$tags$1$job$1.invokeSuspend(Database.kt:41)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
期望与发现之间的区别是
Expected:
creation=Column{name='creation', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0}
Found:
Date=Column{name='Date', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0}
这是我的Tag类的样子。
@Entity(tableName = "tags")
class Tag(@PrimaryKey val name: String, val type: Int, var isFavorite: Boolean = false,@ColumnInfo(name = "creation") val creation: Date? = null)
有两个问题。列名(应为“ creation”)为Date,我的日期列不能包含null
。
有人知道为什么会这样吗?
答案 0 :(得分:1)
已修复: “预期”表示Room希望该表包含这些列, “找到”是数据库文件中的列。