Realm migration needed without Realm changes
See original GitHub issueGoal
Update my application without need to migrate Realm, or provide a migration that works for all cases
Expected Results
Application updated without RealmMigrationNeededException.
Actual Results
Sometimes I’m getting a RealmMigrationNeededException, sometimes I don’t. Reference: [https://stackoverflow.com/questions/47210891/realm-migration-required-without-realm-structure-changes] @cmelchior answered my there, but I still can’t understand what’s going on.
Steps & Code to Reproduce
- Publish an android app with build version number 24.
- Realm schema version number is the same as build version number. Make no changes to Realm objects, update it to 25, ou 26, or 27.
No migration should be required but it does. And providing a simple code as listed below works for some cases but doesn’t in other cases. I’m getting all kinds of migration exception messages, from
Field count is more than expected - expected 4 but was 5
The ‘Table’ class is missing from the schema for this Realm.
But it doesn’t happen everytime, that’s why it bugs me, I’ve tested with all app versions that I had on store. Installed, logged in, and then installed my newer version with my migration, it never breaks. But I’m getting fabric crashes like thoses listed above in some cases. I trying to understand a couple of things. Like why it happens sometimes only? And why Realm is asking for a migration since I didn’t change anything in any RealmObject? I already made some changes, changed build version and Realm didn’t ask for any migration, which I think it’s the correct behavior. I’m avoiding to go to deleteRealmIfMigrationNeeded because I don’t know how many users will have their data erased. But it looks like it’s the only way to workaround this issue.
Code Sample
if (oldVersion == 24) {
oldVersion++;
}
This is my AppClass code to get Realm configuration:
Realm.init(this);
realmConfiguration = new RealmConfiguration.Builder()
.schemaVersion(BuildConfig.VERSION_CODE)
.migration(new MigrationUtil())
.build();
Realm.setDefaultConfiguration(realmConfiguration);
And this is the changes I’ve made to force a deleteRealm in case a migration exception occurs(which i left it commented for now)
Realm.init(this);
realmConfiguration = new RealmConfiguration.Builder()
.schemaVersion(BuildConfig.VERSION_CODE)
.migration(new MigrationUtil())
.build();
Realm.setDefaultConfiguration(realmConfiguration);
try{
Realm realm = Realm.getInstance(realmConfiguration);
realm.close();
}catch(RealmMigrationNeededException e){
Realm.deleteRealm(realmConfiguration);
}
Realm.getInstance(realmConfiguration);
Version of Realm and tooling
Realm version(s): 3.3.2
Realm sync feature enabled: no
Android Studio version: 3.0.0
Which Android version and device: Android versions 5, 6 and 7 Devices list: TCL 8050E LG K8 LTE ASUS_Z017DC Samgung Galaxy J7
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (8 by maintainers)
@Zhuinden My pleasure, you have my thanks for helping me so much with Realm.
And I just added My final proguard-rules looked like this:
@Zhuinden It works!!! Man, I’m so happy, you have no idea, it worked like a charm, I have no words to describe how amazing this is. Really, I should buy you a beer! This is one of many reasons why working with Realm is so much fun.