question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sugar Migration Issue

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
shuaibq3commented, Apr 28, 2016

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 file

0reactions
FalinChcommented, Apr 27, 2016

Hi, i got the same problem, have you solve the problem? How? Really need help 😦 Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating From a Broken Instance to a Clean Install
Make a complete backup of your broken instance. This includes both the filesystem and database. Extract the contents of your downloaded Sugar ......
Read more >
The Barbaric History of Sugar in America - The New York Times
How sugar became the “white gold” that fueled slavery — and an industry that continues to exploit black lives to this day.
Read more >
The Bitter Work Behind Sugar - Reveal News
On a vast plantation in the Dominican Republic, Haitian migrants still use machetes to harvest sugarcane that's exported to the U.S. The ...
Read more >
How Sugar Changed the World | Live Science
Noting sugar cane's potential as income for the new settlements in the Americas — Europeans were already hooked on sugar coming from the...
Read more >
H-2 Guest Workers and Florida Sugar - Migration Dialogue
Labor. Almost all of Florida's sugar cane was cut by 10,000 Jamaican guest workers in the 1980s. Workers were recruited in Jamaica during...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found