ios - 无法在路径“var/mobile/container/Data/Application/XXXX/Documents/default.realm”打开领域
问题描述
我的应用程序现在已经上线,之后我在领域数据库中进行了一些更改,并且我将领域版本从 18 增加到 19,当我在以 19 增加领域版本后运行我的项目时,我得到了如下所示的错误。
Error Domain=io.realm Code=2
"Unable to open a realm at path '/var/mobile/Containers/Data/Application/D75C5A0A-AAF2-46F5-BDB1-FC738C72EEA4/Documents/default.realm': Invalid top array (ref: 256344, size: 11)
代码
class RealmDB {
// older version is 18
fileprivate static let realmVersionn:UInt64 = 19
static func migrateIfNeeded() {
let config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: realmVersionn,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldVersion < realmVersionn) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
print("### Realm DB has migrated.")
}
})
Realm.Configuration.defaultConfiguration = config
do {
let _ = try Realm()
} catch let error {
AlertView.show(message: error.localizedDescription) {(_) in}
print("REALM Error : ",error)
}
}
}
请不要降级这个问题,我知道以前有人问过这个问题,但我没有从那里找到可靠的解决方案。
如果你在这方面发现了什么,请告诉我。提前致谢。
解决方案
推荐阅读
- matlab - 更新绘图数据的有效方法
- java - 在数据库中创建具有权限的新用户
- wordpress - Wordpress rss-feed 未显示帖子的完整文本
- python - TensorFlow 的训练成本变成了 nan
- jquery - 向 Ajax/jQuery 表单添加附件
- groovy - 如何在 Jenkins 脚本化管道中创建并行阶段?
- python - 如何强制 pip 获取 wheel 包(即使是包依赖项)?
- c# - 使用 CustomWebApplicationFactory 进行 Asp.Net 核心集成测试 - 它是如何工作的?
- python - 如何在不插补的情况下处理 KNN 中的缺失数据?
- c++ - 没有初始化列表的构造函数,具有已删除构造函数的对象