Android 如何通过从资产中销毁和重新加载数据库来迁移房间数据库

Android 如何通过从资产中销毁和重新加载数据库来迁移房间数据库,android,android-sqlite,database-migration,android-room,Android,Android Sqlite,Database Migration,Android Room,我正在使用我的应用程序数据库。我需要将版本从1更改为2,并且正确的.db已嵌入我的应用程序文件夹assets/databases/ 我可以使用addMigrations()指定迁移方法,也可以使用fallbackToDestructiveMigration() fallbackToDestructiveMigration()清空我的数据库,我不知道如何从我的文件夹assets/databases/中再次填充它。也许我可以在FallbackToDestructive迁移发生时指定回调 如果我添加了

我正在使用我的应用程序数据库。我需要将版本从1更改为2,并且正确的.db已嵌入我的应用程序文件夹
assets/databases/

我可以使用
addMigrations()
指定迁移方法,也可以使用
fallbackToDestructiveMigration()

fallbackToDestructiveMigration()
清空我的数据库,我不知道如何从我的文件夹
assets/databases/
中再次填充它。也许我可以在FallbackToDestructive迁移发生时指定回调

如果我添加了迁移方法,那么expected和found之间的差异太大,而且我不知道如何将某些列设置为“notnull”

预期: TableInfo{name='poi',columns={sound\u path=Column{name='sound\u path',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, name\u FR=列{name='name\u FR',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},text\u FR=列{name='text\u FR', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, 地址=列{name='address',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},city=Column{name='city', type='INTEGER',affinity='3',notNull=true,primaryKeyPosition=0}, text_EN=列{name='text_EN',type='text',affinity='2', notNull=false,primaryKeyPosition=0}, video_path=列{name='video_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, 开放时间=列{name='开放时间',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, img_360_paths=列{name='img_360_paths',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, open_schedule_EN=列{name='open_schedule_EN',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, closed_days=列{name='closed_days',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, open_schedule_FR=列{name='open_schedule_FR',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, category\u id=列{name='category\u id',type='INTEGER',affinity='3', notNull=true,primaryKeyPosition=0}, img_path=列{name='img_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, closing_hour=列{name='closing_hour',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},price=Column{name='price', type='INTEGER',affinity='3',notNull=true,primaryKeyPosition=0}, game_path=列{name='game_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},can_skip=Column{name='can_skip', type='INTEGER',affinity='3',notNull=true,primaryKeyPosition=0}, id=列{name='id',type='INTEGER',affinity='3',notNull=true, primaryKeyPosition=1},closed_months=列{name='closed_months', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, vr_path=列{name='vr_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},name_EN=列{name='name_EN', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, 外键=[],索引=[]} 查找时间:08-09 17:27:47.990 22583-22583/com.rendrsoftworks.vrlib E/AndroidRuntime:TableInfo{name='poi', columns={sound_path=Column{name='sound_path',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, name\u FR=列{name='name\u FR',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},text\u FR=列{name='text\u FR', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, 地址=列{name='address',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},city=Column{name='city', type='INTEGER',affinity='3',notNull=false,primaryKeyPosition=0}, text_EN=列{name='text_EN',type='text',affinity='2', notNull=false,primaryKeyPosition=0}, video_path=列{name='video_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, 开放时间=列{name='开放时间',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, img_360_paths=列{name='img_360_paths',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, open_schedule_EN=列{name='open_schedule_EN',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, closed_days=列{name='closed_days',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, open_schedule_FR=列{name='open_schedule_FR',type='TEXT', affinity='2',notNull=false,primaryKeyPosition=0}, category\u id=列{name='category\u id',type='INTEGER',affinity='3', notNull=false,primaryKeyPosition=0}, img_path=列{name='img_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0}, closing_hour=列{name='closing_hour',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},price=Column{name='price', type='INTEGER',affinity='3',notNull=false,primaryKeyPosition=0}, game_path=列{name='game_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},can_skip=Column{name='can_skip', type='INTEGER',affinity='3',notNull=false,primaryKeyPosition=0}, id=列{name='id',type='INTEGER',affinity='3',notNull=false, primaryKeyPosition=1},closed_months=列{name='closed_months', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, vr_path=列{name='vr_path',type='TEXT',affinity='2', notNull=false,primaryKeyPosition=0},name_EN=列{name='name_EN', type='TEXT',affinity='2',notNull=false,primaryKeyPosition=0}, 外键=[],索引=[]}


我也面临同样的问题。您不必运行这些方法
fallbackToDestructiveMigration()
addMigrations()
,至少在上述情况下不必运行。只需使
poi
类与db表相同,并检查符号,例如,错误消息中显示的
poi
表似乎在中有一个不同的字段