-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
delete/recreate realm if migration failed #4552
Comments
Something like this in a wrapper method should work:
In the future, this kind of questions are better asked on Stack Overflow where more people will be able to answer it. |
I'm trying to implement what @cmelchior mentioned: Realm realm;
RealmConfiguration config = getConfig();
try {
realm = Realm.getInstance(config); // Will migrate if needed
} catch (RealmMigrationNeededException e) {
Realm.deleteRealm(config);
realm = Realm.getInstance(config);
}
return realm; However, I'm consistently getting the following exception when the migration fails: I've simplified my workflow to make sure it's the only instance I'm trying to open. |
Is there a solution for that ? |
You can also try my slightly experimental lib called RealmAutoMigration, it works for Realm 4.x+ if you annotate your RealmList fields with Make sure you |
I can't really use experimental lib in professional project i think.. =x Maybe i missed something in changelog.. |
Technically it's "experimental" only because I was lazy to write automated integration tests, but otherwise it works Either way, if nothing works, you can check the current schema version without opening a typed realm using |
I tried to check with DynamicRealm and it's working yes. Thanks @Zhuinden ! |
is there any other way to fix it except for auto migration? |
the solution by @jpmcosta used to work this a new regression in 4.1.1 as far as I can tell. |
It's easy to delete realm when migration needed in config. But I'd like to do a migration and delete realm only if migration failed.
I've tried to wrap migration code in try/catch block but
realm.deleteAll()
does not do the trick.Please provide some documentation on this.
And BTW. Do the migration is performed in transaction ? Sometimes it looks like failed migration broke the data so fixed migration does not help...
Thanks in advance
The text was updated successfully, but these errors were encountered: