Realm Migration: Non-default realms needed to be migrated on default realm migration again

There are two realm configurations on my app. One as default and the other for other uses. The default configuration(as from the documentation, it automatically creates a default.realm):

config = new RealmConfiguration.Builder()

.schemaVersion(2)

.migration(defaultMigration)

.build();

and the normal realm configuration is:

normalConfig = new RealmConfiguration.Builder()

.name("normal_realm")

.schemaVersion(3)

.migration(myMigration)

.build();

the normal_realm contains a Realm table "Student", which has two fields 'name'. so, adding another field 'age' would require the migration for normal_realm is,

private static RealmMigration myMigration = new RealmMigration() {

@Override

public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {

RealmSchema schema = realm.getSchema();

if (oldVersion == 0) {

oldVersion++;

}

if (oldVersion == 2) {

if (!schema.get(Student.class.getSimpleName()).hasField("age")) {

schema.get(Student.class.getSimpleName()).addField("age",...

Read More »

By: StackOverFlow - Tuesday, 13 March

Related Posts