RLMException,对象类型需要迁移 [英] RLMException, Migration is required for object type
问题描述
我有一个对象NotSureItem,其中我有三个属性'title',其名称从'text'和我之后添加的textDescription以及dateTime属性重命名。现在,当我要运行我的应用程序时,它会在我想要向这些属性添加内容时崩溃。它显示以下语句。
I have an object NotSureItem in which I have three property 'title' whose name is renamed from 'text' and textDescription which I had added later and a dateTime property. Now when I am going to run my app it crashes when I want to add something to these properties. It shows following statements.
'由于以下错误,对象类型'NotSureItem'需要迁移:
- 最新对象中缺少属性'text'模型。
- 属性标题已添加到最新的对象模型中。
- 属性'textDescription'已被添加到最新的对象模型。'
'Migration is required for object type 'NotSureItem' due to the following errors: - Property 'text' is missing from latest object model. - Property 'title' has been added to latest object model. - Property 'textDescription' has been added to latest object model.'
这是我的代码:
import Foundation
import Realm
class NotSureItem: RLMObject {
dynamic var title = "" // renamed from 'text'
dynamic var textDescription = "" // added afterwards
dynamic var dateTime = NSDate()
}
推荐答案
只需删除您的应用并再次运行。
Just delete your app and run it again.
每次更改您的Realm上的属性对象现有数据库与新数据库不兼容。
Everytime you change properties on your Realm objects your existing database becomes incompatible to the new one.
只要您还处于开发阶段,您只需从模拟器/设备中删除该应用程序并再次启动即可。
As long as you are still in the developing stage you can simply delete the app from the simulator / device and start it again.
稍后当您的应用程序发布并且您更改对象的属性时,您必须实现向新数据库版本的迁移。
Later when you app has been published and you change properties on your objects you have to implement a migration to the new database version.
这篇关于RLMException,对象类型需要迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!