I used SugarORM in my application's first release. Now, I'm working on the 2nd release, which has new tables added to DB.
According to SugarORM documentation "Sugar will automatically create tables for new entities, so your migration script only needs to cater for alterations to existing tables."
Here's what I done:
<meta-data android:name="VERSION" android:value="2" />
public class NewModel extends SugarRecord<NewModel>
When ran the app, Sugar created the new table, but unfortunately, it also dropped/created existing tables, erasing all data saved locally!
I also tried to create the new table myself, by adding a migration script file 2.sql
which contains my CREATE TABLE NEW_MODEL
statement. Unfortunately too, it threw an exception "Table already exists" because Sugar created the new table and then tried to run my script!
Any suggestions?
I came to a solution, of which I have to create an empty migration script file with the new version number! Now, it creates the new table without dropping/creating my old tables.
So, to conclude:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With