I created my original app using Kivy for Python. Since then, I decided to port it over to Java and have re-built it in Android Studio. The app has an SQLite database that needs to be updated (new table, more entries, etc).
I saw the the onUpgrade()
function can be used to do this, but it looks like the way it works is that I have to specify the old database version and then specify the new one I am updating with.
However when creating the original version, I don't specify a database version.
How do I then update the SQLite database within the app? For this version, I'm more than happy to delete the old database and add in the new one as it's currently not using any data specific to the user.
You only need to clone the table
CREATE TABLE copied AS SELECT * FROM mytable WHERE 0
Where mytable = 'Your table'
Also you can delete the table and recreate the scheme, but first you should do a backup
You have two possible solutions:
0
and perform any required upgrade process. To keep track of the database version, I suggest a Version
table where you have just a few fields: VersionNumber
, UpgradeDate
.
Anytime you upgrade the database schema, you need to update the Version
table with the version you have upgraded to.
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.