After doing a migration, i cant use the Realm.getInstance(context);
anymore
Error: java.lang.IllegalArgumentException: Configurations cannot have different schema versions if used to open the same file. 1 vs. 0
i saw that i must use the created configs previosly to do the migration
RealmConfiguration config1 = new RealmConfiguration.Builder(this)
.schemaVersion(1)
.migration(new Migration())
.build();
now i must create the config1 again everywhere i use the
Realm.getInstance(context);
i used to add this for each method to avoid any kind of null
public List<CustomClass> getAll() {
realm = Realm.getInstance(context);
....
}
public CustomClass getOneById(int id) {
realm = Realm.getInstance(context);
...
}
and sometimes outside the DAO class where i dynamically change the database i use this:
Realm.getInstance(context).beginTransaction();
change object
Realm.getInstance(context).commitTransaction();
now i must create this CONFIG1 (RealmConfiguration) EVERYWHERE? or is there any other approach?
i tried adding to the MainClass this Realm.setDefaultConfiguration(CONFIG1);
but no success =/
i was wrong for checking or avoiding null on realm object calling the getInstance for each method?
Use Realm.setDefaultConfiguration(CONFIG1);
to set default configuration :
and use Realm.getDefaultInstance();
to get default realm instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With