Room 数据库升级问题 IllegalStateException: Migration didn‘t properly handle xxx

  • Post author:
  • Post category:其他


Migration升级数据库

有时需要更改现有的数据库架构。如果我们将添加,更新或删除数据库中的某些字段然后运行我们的应用程序,我们将看到来自Room的异常:

java.lang.IllegalStateException: Migration didn't properly handle xxx
Expected:
TableInfo{name='print_setting', columns={enable_original_amount=Column{name='enable_original_amount', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0, defaultValue='null'}, explain=Column{name='explain', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'},foreignKeys=[], indices=[]}
 Found:
TableInfo{name='print_setting', columns={enable_original_amount=Column{name='enable_original_amount', type='BOOLEAN', affinity='1', notNull=true, primaryKeyPosition=0, defaultValue='null'}, explain=Column{name='explain', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, 
defaultValue='null'}}, foreignKeys=[], indices=[]}

对比发现属性为bool值时,定义字段时应使用INTEGER,而不是BOOLEAN。

android.database.sqlite.SQLiteException: near “AUTO_INCREMENT”: syntax error (Sqlite code 1 SQLITE_ERROR): , while compiling:

改为AUTOINCREMENT

CREATE TABLE `pay` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `bill_code` TEXT)



版权声明:本文为zhouxinxin250原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。