简体   繁体   中英

Android change database in new version off app

Two month ago I published an app in the Google Play Store. Now I want to release a new version of the app but I have to modify the database. I have to create some new columns and have to delete some but now I'm scared that my users will lost their data. What is the best way of changing the databse without to lose any data?

Assuming you use SQLiteOpenHelper , increment your database version you pass to its constructor. The onUpgrade() callback will be called so you can migrate your schema and user data properly.

You can use ALTER TABLE to add columns. To delete columns, you'll have to create a new table, copy the data over and then delete the old table. (You can use ALTER TABLE to rename tables, too.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM