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.
Asked
Active
Viewed 7,133 times
5
ishaan
- 1,831
- 1
- 18
- 30
Mr Magloire
- 673
- 7
- 10
-
see https://pub.dartlang.org/documentation/sqflite/latest/sqflite/openDatabase.html – pskink Jan 08 '19 at 16:45
-
Could you please explain more about what you are asking and edit your title. – El.Hum Jan 08 '19 at 16:45
-
In production version I have sqflite version 3, so should I change this version for the next update? – Mr Magloire Jan 08 '19 at 18:20
2 Answers
12
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
onUpgradecopy 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.
Suragch
- 428,106
- 278
- 1,284
- 1,317
2
I have the same problem and found this article which seems to be a good solution.
cwhisperer
- 1,432
- 1
- 31
- 54