xcode 'RLMException',原因:'由于以下错误,需要迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38343366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:02:20  来源:igfitidea点击:

'RLMException', reason: 'Migration is required due to the following errors

iosobjective-cxcoderealm

提问by AnswerZhao

When i debug the app, i add a new property (@property NSString *haha;),but it show the following exception:

当我调试应用程序时,我添加了一个新属性(@property NSString *haha;),但它显示以下异常:

Terminating app due to uncaught exception 'RLMException', reason: 'Migration is required due to the following errors: 
- Property 'haha' has been added to latest object model.'

But when i add the ignoredProperties, it works well:

但是当我添加 ignoreProperties 时,它运行良好:

+ (NSArray *)ignoredProperties {
    return @[@"thead"];
}

Why? Thx.

为什么?谢谢。

回答by Dickson Leonard

When your app is live / launched you need to do migration when changing your db model. You can refer to Realm's migration docs

当您的应用程序上线/启动时,您需要在更改数据库模型时进行迁移。你可以参考 Realm 的迁移文档

Meanwhile I believe you're still in the process of developing your app. You can just delete / uninstall from your simulator or device and rerun your code

同时,我相信您仍在开发您的应用程序的过程中。您可以从模拟器或设备中删除/卸载并重新运行代码

回答by CodeBender

Because you need to delete the app and reinstall it to reflect the changes to your Realm objects.

因为您需要删除应用程序并重新安装它以反映对 Realm 对象的更改。