How to update an SQLite Database and NOT lose all existing data?

后端 未结 2 1755
北荒
北荒 2021-02-20 11:36

I\'m adding a table to my app\'s SQLite DB. All my syntax there is fine, not the issue. But I\'m having some trouble getting the new table to be created properly. I added the ne

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 12:10

    You can do anything you want in onUpgrade. You can use ALTER to add new columns to your table.

    Worst case, if your schema is completely and entirely different, you'll have to create the new table, populate it using data from the old table, and then delete the old table.

    In any case, onUpgrade was designed to allow for a smooth upgrade without any loss of data. It's just up to you to implement it properly.

提交回复
热议问题