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

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)

你可能感兴趣的:(Android)