realm-java: RealmMigrationNeededException: Field count is more than expected - expected 10 but was 11
Hi, I have problem with migration in my application. All time logcat gives me “io.realm.exceptions.RealmMigrationNeededException: Field count is more than expected - expected 10 but was 11 after migration”.
My old model:
@PrimaryKey
private int sid;
private String title;
private String noSpecialCharsTitle;
private String lang;
private String img;
private String icon;
private boolean owned;
private boolean favorite;
private int favouritePosition = Integer.MAX_VALUE;
My new model:
@PrimaryKey
private int sid;
private String title;
private String noSpecialCharsTitle;
private String lang;
private String img;
private String icon;
private boolean owned;
private boolean favorite;
private int favouritePosition = Integer.MAX_VALUE;
private int stationPosition = Integer.MAX_VALUE;
Migration:
RealmConfiguration realmConfig = new RealmConfiguration.Builder()
.schemaVersion(SCHEMA_VERSION)
.migration((realm, oldVersion, newVersion) -> {
if(oldVersion == 0) {
final RealmObjectSchema station = realm.getSchema().get("Station");
station.addField("stationPosition", int.class);
oldVersion++;
}
})
.build();
Realm.setDefaultConfiguration(realmConfig);
What’s wrong with this migration? Why app always throws RealmMigrationNeededException?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (15 by maintainers)
Commits related to this issue
- RealmResults is always live-to-updated This is the precondition of fine grained notifications. OS will trigger the collection notification immediately when transaction begins on the local thread to c... — committed to realm/realm-java by beeender 7 years ago
- RealmResults is always live-to-updated This is the precondition of fine grained notifications. OS will trigger the collection notification immediately when transaction begins on the local thread to c... — committed to realm/realm-java by beeender 7 years ago
- RealmResults is always live-to-updated This is the precondition of fine grained notifications. OS will trigger the collection notification immediately when transaction begins on the local thread to c... — committed to realm/realm-java by beeender 7 years ago
You may as well just set
deleteIfMigrationNeeded()
on the RealmConfiguration thenIf you have a Realm file, model classes and migration steps which can reproduce the error, we will appreciate if you can share it all.
@kneth Fortunately i’m MacOS user. I opened database in Realm Browser. I found 11th field - ‘position’. In migration i don’t have this field. I changed stationPosition to position in model and now everything works fine, but it’s a little odd.