Flutter - How to update the table structure in Sqflite?

强颜欢笑 提交于 2019-12-24 11:58:50

问题


My app is in production and I want to manage user data when user updates the app without loss of their data, how can I achieve this with sqflite. Explicitly I want to add a column and delete another.


回答1:


You can probably add a column using raw sql, but sqlite (and thus sqflite) doesn't support dropping a column. For that you would need to do the following:

  • increase the database version number
  • in onUpgrade copy the old database columns to a temporary table
  • delete the original table
  • create a new table using the original table name but with the right schema
  • copy the data from the temp table
  • delete the temp table

Sorry, this isn't a full answer, but it is the direction I would go if I were in your situation.




回答2:


I have the same problem and found this article which seems to be a good solution.



来源:https://stackoverflow.com/questions/54095892/flutter-how-to-update-the-table-structure-in-sqflite

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