Skip to content

Instantly share code, notes, and snippets.

@alhazmy13
Last active March 15, 2016 11:30
Show Gist options
  • Save alhazmy13/ce7a1d2795a8b42110ec to your computer and use it in GitHub Desktop.
Save alhazmy13/ce7a1d2795a8b42110ec to your computer and use it in GitHub Desktop.
RealmMigration must be provided
If you don't have any problem in loosing your old data then you can delete Realm Configuration and create new one.
-------------------------------------------------------------------------------
Realm realm = null;
try {
realm = Realm.getInstance(MainActivity.this);
} catch (RealmMigrationNeededException r) {
Realm.deleteRealmFile(MainActivity.this);
realm = Realm.getInstance(MainActivity.this);
}
-------------------------------------------------------------------------------
OR to keep your data
-------------------------------------------------------------------------------
RealmConfiguration config2 = new RealmConfiguration.Builder(this)
.name("default2")
.schemaVersion(3)
.deleteRealmIfMigrationNeeded()
.build();
realm = Realm.getInstance(config2);
-------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment