I used Realm in my android untill now with
new RealmConfiguration.Builder(this) .build();
I just read later about the possibility to add schema and migration. So in my new version for my app i want to add the migration feature. so i changed the line above to:
new RealmConfiguration.Builder(this) .schemaVersion(0) .migration(new Migration()) .build();
but now I get the error
IllegalArgumentException: Configurations cannot be different if used to open the same file.
How can i change the configuration without deleting the database
I think your problem is that you are creating your RealmConfiguration multiple times. That shouldn't be a problem by itself (although it is inefficient), but the problem arises with your Migration
class. Internally we compare all state in the configuration objects and if you didn't override equals
and hashCode
in your Migration
class you have a case where new Migration().equals(new Migration()) == false
which will give you the error you are seeing.
One solution is adding this:
public class Migration implements RealmMigration {
// Migration logic...
@Override
public int hashCode() {
return 37;
}
@Override
public boolean equals(Object o) {
return (o instanceof Migration);
}
}
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