Opening Realm files of format version 0 is not supported by this version of Realm

Viewed 813

We have been using Realm from the past year, We recently upgraded the application from V6.1.0 to V7.0.0, post this upgrade we are witnessing the crash mentioned, we are using Kotlin for application development with Realm java and lastly, we have enabled DB encryption

java.lang.RuntimeException: Unable to create application com.myapp.Application: io.realm.exceptions.RealmFileException: Opening Realm files of format version 0 is not supported by this version of Realm (Database has an unsupported version and cannot be upgraded
Exception backtrace:
(/data/data/com.myapp.Application:/files/myapp.realm) in /Users/cm/Realm/realm-java-release/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp line 107 Kind: FORMAT_UPGRADE_REQUIRED.
at io.realm.internal.OsSharedRealm.nativeGetSharedRealm(Native Method)
at io.realm.internal.OsSharedRealm.(OsSharedRealm.java:175)
at io.realm.internal.OsSharedRealm.getInstance(OsSharedRealm.java:251)
at io.realm.BaseRealm.(BaseRealm.java:137)
at io.realm.BaseRealm.(BaseRealm.java:104)
at io.realm.Realm.(Realm.java:163)
at io.realm.Realm.createInstance(Realm.java:499)
at io.realm.RealmCache.createInstance(RealmCache.java:507)
at io.realm.RealmCache.doCreateRealmOrGetFromCache(RealmCache.java:473)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:414)
at io.realm.Realm.getDefaultInstance(Realm.java:407)```


2 Answers

7.0.o is still in BETA, I believe they will add support for migration when it hits stable. Also I would not recommend use it for production in beta phase.

This was a migration problem for me after I updated the Realm version. Deleting all old RealmModels inside the migration block will not help. The entire Realm database needs to be deleted in this case.

On iOS, during Realm configuration, there exists the property deleteRealmIfMigrationNeeded. By setting it to true has fixed the problem for me.

As I understand, for Java, it would require to simply call the function .deleteRealmIfMigrationNeeded(). Something similar to this:

Realm.init(this);
realmConfiguration = new RealmConfiguration.Builder()
            .schemaVersion(BuildConfig.REALM_SCHEMA_VERSION)
            .migration((realm, oldVersion, newVersion) -> RealmAutoMigration.migrate(realm))
            .deleteRealmIfMigrationNeeded()
            .build();

Realm.setDefaultConfiguration(realmConfiguration);
Related