Android SQLite Database, WHY drop table and recreate on upgrade

后端 未结 5 1940
小蘑菇
小蘑菇 2020-11-28 06:12

In the tutorials I am following and a lot of more places I see this, onUpgrade -> drop table if exists, then recreate table.

What is the purpose of this?

<         


        
5条回答
  •  萌比男神i
    2020-11-28 06:20

    I agree when you upgrade you should be adding columns or adding tables to your database. Most of the onupgrade samples actually suck because why am I deleting all this data then recreating the table? I found this blog entry I call it the Adams Incremental Update Method. It also handles situations where users may have not upgraded your app with each release.

    Here is a good blog on sqlite onupgrade that doesn't do drop table.

提交回复
热议问题