-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrading database Sugar ORM always delete previous table's data #422
Comments
Have you tried using migrations? Check them out http://satyan.github.io/sugar/migration.html |
No, I didn't tried this becasue it makes no sense write a sql script to create a new table since I created a new SugarRecord class (it should create the table automaticaly to me, right?). In my opinion, this "upgrade script" should be use only to alter something that already exists, or drop some table... . Am I right? |
I am not a developer for this project but here is my understanding of how it works... When you modify or create a new table (Sugar Record) you have to upgrade the version number in the manifest. -When you iterate the version number in the manifest, WITHOUT ANY MIGRATION SQL SCRIPTS, it will wipe away all your old tables and create the new ones in order to be certain that the new tables are correct; this is why your previous data is gone. So, in this case, it would appear you are going to want to go with the migration yourself and write your own SQL for creating the new table you need, that is the only way to keep your old data. |
I've made some tests right now:
Conclusion: doesn't matter what I do, if I create a new SugarRecord on my project, every data is wiped. This is awful ... |
In case somebody stumbles upon this: I just had the same use case and tested my app extensively with the beta 1.4 sugar orm. The trick is to put an empty script in the migrations folder. Then, the existing tables are not dropped and recreated and only the new tables are created. This works great for new features, where the existing data model remains unchanged and only new models were included! |
Just want to add to peshkira's statement: I've tried the same thing with version 1.3 and it does not works. |
any update on this issue ? is this solved ? |
Hi, I'm using version 1.4 of Sugar and I get the same error. I realized that by only incrementing VERSION number in manifest file don't update existing table. At the same time, as suggested by @peshkira, only creating an empty script also don't solve the problem. The Migration doc (http://satyan.github.io/sugar/migration.html) said that "Sugar will also automatically create fields for existing tables when you add new fields to your Sugar models". But it's not working for me. For solve this:
The trick here is: after add new table column, the VERSION number SHOULD be incremented and you SHOULD create SQL script file containing instructions to update. Otherwise it not work. Additionally: my table data was not wiped after update! ;) |
@taynanb could you try with 1.5 or master version |
Hi @sibeliusseraphini, GREAT! I tested using Sugar 1.5 and works fine without creating script, only incrementing VERSION number in manifest. Also, I did not need to create constructors for table model. Thank you! UPDATE: I said "I did not need to create constructors for table model". But, if I create a signed constructor I also SHOULD create default construtor for Sugar work correctly! Otherwise your row will be created but will not be able to read then. |
@taynanb thanks |
@sibeliusseraphini I updated my last comment about constructor! Thanks |
Migration stuff with 1.5, showing duplicate column exists. |
I have two reports of this happening from users who have updated from the Play store but I could not find any valuable clues from either report. Users simply report upgrading from one version of the app to another. In both cases the update in question did NOT have a new database version value in the I don't know if this is Sugar related but was hoping to possibly find an answer here. I have done DB updates in the past and this is how I've implemented them:
I'd be grateful if anyone could provide any further information. (Using Sugar 1.5) |
Hello, you say there was no new db version. |
Based on the information that I've gathered from these users, no. In other words they updated to a version of the app that had no schema changes/no new db version. I'm sorry I'm light on details. It was a longshot posting this here, but I decided to since all SQLite interaction in this app is done through Sugar and it seemed like a likely culprit. |
Plausible assumption. But since the db version doesn't change, the upgrade code is never called so I doubt the problem is related to the above code. |
I have a database with Sugar ORM, and every time I create a new class that extends SugarRecord, I need to upgrade my database_version on android manifest to Sugar ORM recognize the new table. Ok till then.
The problem is that Sugar ORM is deleting all my previous data on every table of my database! I have a lot of data on them, and I can't delete it and reinsert it on every database upgrade.
There is some way to avoid this?
Thanks
The text was updated successfully, but these errors were encountered: