Swift Realm Property’*’已被添加到最新的对象模型MIGRATION中

Swift Realm Property’*’已被添加到最新的对象模型MIGRATION中,第1张

概述我已经将新的数组属性添加到R​​LMObject和 public class Student: RLMObject { dynamic var id = 0 dynamic var name = "" dynamic var resultList = RLMArray(objectClassName:Result.className())}public class R 我已经将新的数组属性添加到R​​LMObject和
public class Student: RLMObject {    dynamic var ID = 0    dynamic var name = ""    dynamic var resultList = RLMArray(objectClassname:Result.classname())}public class Result: RLMObject {}

错误日志:

Migration is required for object type ‘Student’ due to the following@H_502_7@ errors:@H_502_7@ – Property ‘resultList’ has been added to latest object model.

TRY失败:

let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()migration.enumerateObjects(Student.classname()) { oldobject,newObject in    newObject!["resultList"] = RLMArray(objectClassname: Result.classname())}

编辑:

let configuration:RLMRealmConfiguration = RLMRealmConfiguration.defaultConfiguration()    print("Realm db current version: \(configuration.schemaVersion)")    configuration.schemaVersion = 1    configuration.migrationBlock = {(migration:RLMMigration,oldSchemaVersion: UInt64) in        print("Realm db migration start")        if oldSchemaVersion < 1 {            print("Schema version: 1 - Rename fIElds")            migration.enumerateObjects(Student.classname()) { oldobject,newObject in                newObject!["creationDate"] = oldobject!["createdAt"]                newObject!["modifIEdDate"] = oldobject!["updatedAt"]            }        }        print("Realm db migration finish")    }    RLMRealmConfiguration.setDefaultConfiguration(configuration)    let realm = RLMRealm.defaultRealm()

解:

将您的版本更新为1

configuration.schemaVersion += 1
您必须增加schemaVersion并在RLMRealmConfiguration上提供migrationBlock.在那里你可以迁移表.但是你不需要在你的具体情况下.可以自动处理属性的添加.你还需要一个空块.
let config = RLMRealmConfiguration.defaultConfiguration()config.schemaVersion = 1config.migrationBlock = { (migration,oldSchemaVersion) in    // nothing to do}RLMRealmConfiguration.setDefaultConfiguration(config)
总结

以上是内存溢出为你收集整理的Swift Realm Property’*’已被添加到最新的对象模型MIGRATION中全部内容,希望文章能够帮你解决Swift Realm Property’*’已被添加到最新的对象模型MIGRATION中所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1047110.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存