androiddatabaserealmrealm-mobile-platform

Realm restore after altering backup file from Realm Studio


I am building an offline application which uses Realm database. I am giving an backup and restore feature. It is working perfectly and realm is doing a good work with fast synchronization in fraction of time.

I am maintaining various tables on realm. Presently, when I check the datas from realm studio, opening the backup file, I have found few false data postings to the table. As the case, I have altered the necessary datas and tried to restore that file.

This has taken me to an error after restoring, when i access the realm object, it says, the realm table does not exist.

why would this be happening??? is it because when opening realm file and altering we have to do some other operations or something??

java.lang.IllegalArgumentException: The class 'LastTableIdsTable' doesn't exist in this Realm. (/Users/Nabil/Dev/realm/master/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsSharedRealm.cpp:244) at io.realm.internal.OsSharedRealm.nativeGetTable(Native Method) at io.realm.internal.OsSharedRealm.getTable(OsSharedRealm.java:309) at io.realm.RealmSchema.getTable(RealmSchema.java:187) at io.realm.RealmSchema.getSchemaForClass(RealmSchema.java:209) at io.realm.RealmQuery.(RealmQuery.java:145) at io.realm.RealmQuery.createQuery(RealmQuery.java:84) at io.realm.Realm.where(Realm.java:1332)


Solution

  • when we try to edit the backup realm file from realm studio and restore it, we need to make sure all realm is closed. And we need to delete the old realm, by calling Realm.deleteRealm(), pass configuration if you have set any RealmConfiguration.

    After restore has finished, before opening the realm, you have to initialize the new realm with configurations you need.