realm-java: Exception: RealmMigrationNeededException: RealmMigration must be provided

Goal

What do you want to achieve?

Run migrations and have them work correctly.

Expected Results

I have already provided a migration, yet I’m still getting exceptions.

Actual Results

Caused by io.realm.exceptions.RealmMigrationNeededException: The 'Auth' class is missing from the schema for this Realm. at io.realm.AuthRealmProxy.validateTable(SourceFile:171) at io.realm.DefaultRealmModuleMediator.validateTable(SourceFile:117) at io.realm.Realm.initializeRealm(SourceFile:349) at io.realm.Realm.createAndValidate(SourceFile:314) at io.realm.Realm.createInstance(SourceFile:265) at io.realm.RealmCache.createRealmOrGetFromCache(SourceFile:143) at io.realm.Realm.getDefaultInstance(SourceFile:210)

Steps & Code to Reproduce

In the latest version of my app, I add a new object called “Auth”. I bumped the schema version to 6 and added some lines in my migration helper class to get that done too. Here is how the migration goes:

This is all inside the migrate(DynamicRealm realm, long oldVersion, long newVersion) method:

RealmSchema schema = realm.getSchema();
if (oldVersion == 5) {
			schema.create("Auth").addField("token", String.class);
			oldVersion++;
		}

Why is the migration failing? i’m also getting a exception for another object where I added a field, and it’s expecting 9 but got 8 fields. That shouldn’t be the case either because i fixed that in my migration. To me it seems like the migrations are simply failing.

I remember getting this exception myself when testing because I didn’t add the migration, but before I released it, I added the migration in and testing it again.

Version of Realm and tooling

Realm version(s): 3.0.0

Realm sync feature enabled: no

Android Studio version: Latest stable release.

Which Android version and device: A range, Android 5, 7, 8. Samsung, Google, LG etc

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 36 (18 by maintainers)

Most upvoted comments

One more thing not related with the original issue, Realm.getDefaultInstance().getConfiguration(); will create a anonymous Realm instance which is not closed properly. That may cause leaks.

It creates a default realm right? That’s the experience I had when debugging. I also check for that and delete it.

Anyway thanks, noted it.