androidrealmrealm-migration

Android RealmMigration issue - Migration not applied and still getting io.realm.exceptions.RealmMigrationNeededException


I am having a problem with Realm, the application is crashing on startup when I update my new APK.

Caused by: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors:
    - Property 'TransactionData.retriedOnExpired' has been made required.

The RealmMigration class has the line when that column is added, if I add breakpoints I can see the code being called successfully. However, still the application crashes after the Realm.getDefaultInstance() is called.

So somehow the RealmDatabase is not detecting the migration even though the migration code is executed.


Solution

  • The issue is that if the RealmMigration helper is in Java, the kotlin Boolean classes must be declared as boolean.class instead of Boolean.class

    If the property was declared as a non-nullable Boolean (kotlin) then Realm will expect the FieldAttribute.REQUIRED flag to be set.