How to perform a lightweight migration on sqlite database in Android just the way like iOS? -
i want add keys, such "url", existed table.
in ios, can create new version of data model , perform light weight migration.
however, default way in sqliteopenhelper seems destroy old db , create new one.
@override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // drop older table if existed db.execsql("drop table if exists " + table_1 + ", " + table_2 + ", " + table_3 + ", " + table_4); // create tables again oncreate(db); }
how can keep old database , add new keys in android?
you can write own upgrade sql query upgrade database.
call oncreate after droping tables easy way upgrade tables without caring fks, null fields or database version.
use oldversion , newversion make correct changes (alter table) on database.
Comments
Post a Comment