How to drop and recreate all tables on DB version update in ActiveAndroid?

独自空忆成欢 提交于 2019-12-06 14:31:21

Not sure if I understood correctly but if you are in development then the easiest is to just uninstall the app and let Active Android recreate the DB schema when you install it again.

When in production you will need to use the migration scripts as per their documentation.

I faced a similar issue and I needed to force a few tables to be recreated. Unfortunately you will need to do it manually. However you can use the ActiveAndroid helper classes to help you out.

  1. First you need to process the old table data somehow.
  2. Drop the tables:

    SQLiteUtils.execSql("DROP TABLE IF EXISTS Your_Table_Name");

  3. Recreate the table using the ActiveAndroid classes.

    SQLiteUtils.execSql(SQLiteUtils.createTableDefinition(Cache.getTableInfo(YOUR_MODEL_CLASS.class)));

  4. Insert the old data into your newwly create table.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!