iOS 的领域 DB 抛出架构不匹配错误,提供的架构版本 84 低于最后设置的版本 86
Realm DB for iOS throws a schema mismatch error, Provided schema version 84 is less than last set version 86
我最近对我的项目进行了 pod 更新,从那以后我就遇到了 Realm 问题。
代码如下,
MyNetworkManager.sharedNetworkManager.performNetworkOperation(url: MyEndpoint().homepage(), httpmethod: .get, parameters: requestDict) { response in
let realm = try! Realm()
try! realm.write {
let JSON = response.result.value as AnyObject
realm.create(HomePageData.self, value: JSON, update: true)
}
显示的错误如下,
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=io.realm Code=1 "Provided schema version 84 is less than last set
version 86." UserInfo={NSLocalizedDescription=Provided schema version 84 is
less than last set version 86., Error Code=1}
我阅读了关于同一问题的其他答案,但没有发现任何相似之处。一般来说,我是 Realm 的新手,请告诉我解决这个问题的最佳方法是什么。
项目详情:
- 语言 - Swift 3 和 Objective C 部分
- Swift 的领域用于 DB
- Xcode 版本 - 9.2
您正在新版本上安装旧版本应用(降级)
这就是导致此问题的原因,只需尝试迁移您的数据库
var 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: 87,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 86) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
})
// Tell Realm to use this new configuration object for the default Realm
Realm.Configuration.defaultConfiguration = config
我最近对我的项目进行了 pod 更新,从那以后我就遇到了 Realm 问题。 代码如下,
MyNetworkManager.sharedNetworkManager.performNetworkOperation(url: MyEndpoint().homepage(), httpmethod: .get, parameters: requestDict) { response in
let realm = try! Realm()
try! realm.write {
let JSON = response.result.value as AnyObject
realm.create(HomePageData.self, value: JSON, update: true)
}
显示的错误如下,
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=io.realm Code=1 "Provided schema version 84 is less than last set
version 86." UserInfo={NSLocalizedDescription=Provided schema version 84 is
less than last set version 86., Error Code=1}
我阅读了关于同一问题的其他答案,但没有发现任何相似之处。一般来说,我是 Realm 的新手,请告诉我解决这个问题的最佳方法是什么。
项目详情:
- 语言 - Swift 3 和 Objective C 部分
- Swift 的领域用于 DB
- Xcode 版本 - 9.2
您正在新版本上安装旧版本应用(降级)
这就是导致此问题的原因,只需尝试迁移您的数据库
var 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: 87,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
migrationBlock: { migration, oldSchemaVersion in
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 86) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
})
// Tell Realm to use this new configuration object for the default Realm
Realm.Configuration.defaultConfiguration = config