添加新的核心数据模型版本后出错
我添加了一个新的模型版本,并将核心数据模型设置为使用该新版本,但当应用程序尝试启动时出现此错误。
“用于打开持久存储的托管对象模型版本与用于创建持久存储的版本不兼容。”
我猜测问题在于当前的持久存储是模型的旧版本。有没有办法直接删除它,然后再创建一个新的?我不关心保存任何数据。
I added a new model version, and I set the core data model to use that new version, but I get this error when the application tries to start.
"The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store."
I'm guessing the problem is that the current persistent store is the old version of the model. Is there a way to just delete it so it makes a new one? I don't care about saving any of that data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在版本之间迁移。根据Apple的文档,如果更改很简单,则可以进行轻量级迁移。
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweight.html#//apple_ref/doc/uid/TP40008426-SW1
将这些选项添加到NSPersistentStoreCoordinator 似乎可以工作。
You have to migrate between versions. According to Apple's docs, if the changes are simple, you can do lightweight migration.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweight.html#//apple_ref/doc/uid/TP40008426-SW1
Adding these options to the NSPersistentStoreCoordinator seemed to work.
回答你的问题,“有没有办法删除它,这样它就可以创建一个新的?”
是的。
只需更改 App Delegate 中的 permanentStoreCoordinator getter 即可,如下所示:
In answer to your question, "Is there a way to delete it so it just makes a new one ?"
Yes.
Just change the persistentStoreCoordinator getter in your App Delegate as follows:
找出您的应用程序存储文档的位置并将其放入垃圾箱。
但作为扩展评论,您可能希望检查 NSPersistentStoreCoordinator 中的显式和隐式迁移以及中的选项的可能性。
- (NSPersistentStore *)addPersistentStoreWithType:(NSString *)storeType 配置:(NSString *)configuration URL:( NSURL *)storeURL options:(NSDictionary *)options error:(NSError **)error
根据版本的不同,您可以通过传递
NSMigratePersistentStoresAutomaticallyOption
& 来让它自动发生。NSInferMappingModelAutomaticallyOption
还有
- (NSPersistentStore *)migratePersistentStore:(NSPersistentStore *)store toURL:(NSURL *)URL 选项:(NSDictionary *)options withType:(NSString *)storeType error:(NSError **)错误
Figure out where your app stored the document and put it in the trash.
But as a extended comment you may wish to examine the possibilities around both explicit and implicit migration in NSPersistentStoreCoordinator and the options in.
- (NSPersistentStore *)addPersistentStoreWithType:(NSString *)storeType configuration:(NSString *)configuration URL:(NSURL *)storeURL options:(NSDictionary *)options error:(NSError **)error
Depending how different the versions are you can get it to happen automagically by passing
NSMigratePersistentStoresAutomaticallyOption
&NSInferMappingModelAutomaticallyOption
theres also
- (NSPersistentStore *)migratePersistentStore:(NSPersistentStore *)store toURL:(NSURL *)URL options:(NSDictionary *)options withType:(NSString *)storeType error:(NSError **)error