为什么会抛出此异常(当我尝试迁移多个领域时)?
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;
}
答案 0 :(得分:2)
首先,我需要以正确的方式实例化realmconfig。
RLMRealmConfiguration *someOtherConfig = [[RLMRealmConfiguration defaultConfiguration] copy];
而不是:
RLMRealmConfiguration *someOtherConfig = [[RLMRealmConfiguration alloc] init];
我需要删除其他schemaVersion配置和冗余迁移块:
config.schemaVersion = migrationVersion;
在执行实际迁移之前:
[RLMRealm migrateRealm:someOtherConfig];