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.

Getting io.realm.exceptions.RealmMigrationNeededException randomly

See original GitHub issue

This crash happens randomly when getting Realm configuration and does not happen during the actual migration part.

Realm Configuration Code

private static int realmDBVersion = 10;
        if(mRealmConfiguration==null)
        {
                mRealmConfiguration = new RealmConfiguration.Builder()
                        .name(dbFileName + ".realm")
                        .encryptionKey(password)
                        .schemaVersion(realmDBVersion)
                        .migration(new MyRealmMigration())
                        .build();
        }
        return mRealmConfiguration;

MyRealmMigration code

RealmSchema schema = realm.getSchema();

   if(oldVersion ==9){
            schema.create("CodeTypeItemAuxiliary");

            RealmObjectSchema formMappingAreaSchema = schema.get("FormMappingArea");
            RealmObjectSchema codeTypeItem = schema.get("CodeTypeItem");
            RealmObjectSchema codeTypeItemAuxiliary = schema.get("CodeTypeItemAuxiliary");

            codeTypeItemAuxiliary
                    .addField("objectId",int.class, FieldAttribute.PRIMARY_KEY)
                    .addField("codeTypeItemId", String.class)
                    .addField("formFieldAttribute", String.class)
                    .addField("value", String.class);

            formMappingAreaSchema.addField("formFieldAttribute", String.class);
            codeTypeItem.addRealmListField("codeTypeItemAuxiliaryList",codeTypeItemAuxiliary);

            oldVersion++;
        }

Version of Realm and tooling

Realm version(s): 3.3.1

Realm sync feature enabled: no

Android Studio version: 2.3.3

Which Android version and device: Samsung S7

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Zhuindencommented, Oct 12, 2017

If you did all this config initialization in Application.onCreate() then this problem would not be possible.

0reactions
cmelchiorcommented, Nov 6, 2017

Closing due to no response. @rahulmenezes feel free to reopen if you have new information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Can't avoid io.realm.exceptions ... - Stack Overflow
exceptions.RealmMigrationNeededException: Migration is required due to the following errors: - Primary Key for class 'NoteModel' has been added.
Read more >
TaskTracker Android tutorial fails after schema change
TaskActivity}: io.realm.exceptions.RealmMigrationNeededException: Migration is required due to the following errors: - Property 'Task.
Read more >
RealmTests.java example - Javatips.net
Random ; import java.util. ... RealmMigrationNeededException; import io.realm.exceptions. ... j++) { test_char = test_char_old + chars_array.get(random.
Read more >
Integrating Realm Database in an Android Application - Auth0
Getting Started · buildscript { repositories { jcenter() } dependencies { classpath "io.realm:realm-gradle-plugin:3.1.4" } } · apply plugin: ' ...
Read more >
Realm数据库- Android技巧 - 积木
RealmMigration; import io.realm.exceptions.RealmMigrationNeededException; import java.io.File; import java.util.Random; import android.content.
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