chennaione / sugar

Insanely easy way to work with Android Database.
http://satyan.github.com/sugar/
MIT License
2.62k stars 583 forks source link

Alter Table #697

Open muhammad-umair-khan opened 7 years ago

muhammad-umair-khan commented 7 years ago

Hi,

I have added new columns in a table and followed version upgradation procedure mentioned in documentation, but i am still getting error of no such column. Is there any solution for that or do i need to uninstall app and install it again?

Actually i want to make it work without uninstallation of app. As users will download new version of app, the database should automatically be updated. Thanks

LSchultebraucks commented 7 years ago

Hi, like you can see here i had a similar issue. I solved this by using the SQLiteOpenHelper class. I created a class named SQLHelper, which extends from the SQLiteOpenHelper class. There i handle the upgrade of my tables. Very important is, that you have to create an instance of this SQLHelper class if you start your app. Then onUpgrade() will be called if your Database on you device has a lower number as the database version in you android manifest. You can use db.execSQL() take changes on your database schema. I hope i could help you. Lasse