question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Realm migration needed without Realm changes

See original GitHub issue

Goal

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

  1. Publish an android app with build version number 24.
  2. 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:closed
  • Created 6 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
shidobeckercommented, Nov 27, 2017

@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:

-keepnames public class * extends io.realm.RealmObject
-keep public class * extends io.realm.RealmModel { *; }
-keep @io.realm.annotations.RealmModule class *
-keep class io.realm.** { *; }
-dontwarn javax.**
-dontwarn io.realm.**
-keepattributes *Annotation*
2reactions
shidobeckercommented, Nov 24, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm Migration Required without realm structure changes
It is because the Realm version number is stored internally in the Realm file and that is used as the first check to...
Read more >
Schema Versions & Migrations - React Native SDK — Realm
Realm automatically migrates certain changes, such as new and deleted properties, but does not automatically set values for new properties unless the updated ......
Read more >
Migration with Realm (RealmSwift Part 6) | by Ali Akhtar
Solution 2 (Schema Versioning Automatic Migration)​​ Delete the application and run again with the code shown in Figure 5 and you will see...
Read more >
How to Update Realm SDK Database Schema for Android
In this article, we learn how to modify/migrate Realm local database schema. Introduction. As you add and change application features, you need ......
Read more >
Realm Split FAQ - Salesforce Help
... to the process required to split and migrate part of a live customer realm ... changed to maintenance mode and migration process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found