Migrating multiple realms - Realm Version Greater

2020-05-07 14:51发布

问题:

Why this exception is thrown (when I'm trying to migrate multiple realms)?

bool ObjectStore::is_schema_at_version(Group *group, uint64_t version) {
    uint64_t old_version = get_schema_version(group);
    if (old_version > version && old_version != NotVersioned) {
        throw ObjectStoreException(ObjectStoreException::Kind::RealmVersionGreaterThanSchemaVersion,
                                   {{"old_version", to_string(old_version)}, {"new_version", to_string(version)}});
    }
    return old_version != version;
}

回答1:

First of all I needed to instantiate realmconfig in the right way.

RLMRealmConfiguration *someOtherConfig = [[RLMRealmConfiguration defaultConfiguration] copy];

Instead of:

RLMRealmConfiguration *someOtherConfig = [[RLMRealmConfiguration alloc] init];

And I needed to remove the additional schemaVersion config and redundant migrationblocks:

config.schemaVersion = migrationVersion;

Before performing the actual migration:

[RLMRealm migrateRealm:someOtherConfig];


标签: ios realm