I have a Realm model that I want to apply migrations. However, when I apply the migrations I get the error
Configurations cannot be different if used to open the same file.
The most likely cause is that equals() and hashCode() are not overridden in the migration class:
In my Activity class, the configuration is set as:
realmConfiguration = new RealmConfiguration
.Builder(this)
.schemaVersion(0)
.migration(new Migration())
.build();
I use the realm instance to get some values. And then I apply the migration using:
RealmConfiguration config = new RealmConfiguration.Builder(this)
.schemaVersion(1) // Must be bumped when the schema changes
.migration(new Migration()) // Migration to run
.build();
Realm.setDefaultConfiguration(config);
When I call this: realm = Realm.getDefaultInstance();
I get the error above. Am I applying the migrations correctly?
Your migration should look like this:
public class MyMigration implements Migration {
//... migration
public int hashCode() {
return MyMigration.class.hashCode();
}
public boolean equals(Object object) {
if(object == null) {
return false;
}
return object instanceof MyMigration;
}
}
Have you tried overriding equals
and hashcode
in your Migration
class as the exception message says?
The most likely cause is that equals() and hashCode() are not overridden in the migration class
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