Sugar Migration Issue
See original GitHub issueI am having issues with database migration using SugarORM (1.4) in my Android project.
I want to add 2 columns in an existing table (NOTE).
In the migration SQL script (assets/sugar_upgrades/2.sql), I have:
ALTER TABLE NOTE ADD COLUMN created_by INTEGER REFERENCES USER(id);
ALTER TABLE NOTE ADD COLUMN is_synced INTEGER DEFAULT 0;
I also added 2 integer variables in Note.class, which extends SugarRecord (createdBy, isSynced).
This adds 2 columns to the table. The problem is when I try to retrieve data from NOTE table.
List<Note> note = Note.listAll(Note.class);
: returns an empty list.
List<Note> allNotes = Lists.newArrayList(Note.findAll(Note.class));
: returns the records, but if I write:
allNotes.get(0).setTitle('title');
allNotes.get(0).setBody('body text');
allNotes.get(0).save();
it inserts a new row in the table instead of updating the first row. Further looking into it, I found that:
allNotes.get(0).getId();
: returns null.
Putting a blank upgrade SQL file does not add columns to the table, even if the new integers/columns are defined in Note.class. I also tried putting a blank 1.sql and a 2.sql containing the migration SQLs. Did not work.
In case of creating new tables the migration works fine.
Please let me know what the issue is. If it is a bug please look into it.
Thanking in advance.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6
Top GitHub Comments
Hey @FalinCh , Sugar 1.5 does not have such migration issues. in fact sugar 1.5 does not require any migration sql script. new columns are created once a new field has been added to the entity class (extends SugarRecord). I have added Sugar 1.5 in my project and removed all the migration scripts and its working fine now 😃 check the 1.5 documentation and changeLog for details.
add
compile 'com.github.satyan:sugar:1.5'
to your build.gradle fileHi, i got the same problem, have you solve the problem? How? Really need help 😦 Thanks