我在下面提到的异常中得到了它
迁移未正确处理
Expected:
TableInfo{name='ContactModel', columns={name=Column{name='name', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0},
number=Column{name='number', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1},
isVerified=Column{name='isVerified', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0},
age=Column{name='age', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='ContactModel', columns={number=Column{name='number', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1},
isVerified=Column{name='isVerified', type='Boolean', affinity='1', notNull=false, primaryKeyPosition=0},
name=Column{name='name', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0},
age=Column{name='age', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
查询
val migration2 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
val migString = "ALTER TABLE ContactModel ADD COLUMN isVerified Boolean"
database.execSQL(migString)
}
}
答案 0 :(得分:0)
我遇到了同样的问题,而且Room似乎不支持布尔值,因此您的迁移字符串应为:
val migString = "ALTER TABLE ContactModel ADD COLUMN isVerified INTEGER NOT NULL DEFAULT 0"
,然后可以在代码中将其用作布尔值。