核心数据迁移问题:“持久存储迁移失败,缺少源托管对象模型." [英] Core Data migration problem: "Persistent store migration failed, missing source managed object model."

查看:21
本文介绍了核心数据迁移问题:“持久存储迁移失败,缺少源托管对象模型."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

  • 一个 Cocoa 非文档核心数据具有两个托管对象的项目楷模.
  • 模型 1 保持不变.模型2变了,所以想迁移商店.
  • 我创建了一个新版本按设计 > 数据模型 > 添加模型Xcode 中的版本.
  • 版本之间的区别在于单一关系已从一对多变为一对多.
  • 我做了我的对模型所做的更改,然后保存.
  • 我制作了一个新的映射模型有旧模型作为来源和新的模型作为目的地.
  • 我保证所有映射模型和数据模型并且正在编译,所有都是复制到我的资源文件夹应用程序包.
  • 我已通过以下方式启用迁移传入字典NSMigratePersistentStoresAutomaticallyOption键为 [NSNumbernumberWithBool:YES] 添加时持久存储.
  • 而不是合并捆绑包中的所有型号,我指定了这两个我想使用的模型(模型 1 和新版本的模型 2) 并合并他们使用 modelByMergingModels:
  • A Cocoa Non Document Core Data project with two Managed Object Models.
  • Model 1 stays the same. Model 2 has changed, so I want to migrate the store.
  • I've created a new version by Design > Data Model > Add Model Version in Xcode.
  • The difference between versions is a single relationship that's been changed from to a one to many.
  • I've made my changes to the model, then saved.
  • I've made a new Mapping Model that has the old model as a source and new model as a destination.
  • I've ensured all Mapping Models and Data Models and are being compiled and all are copied to the Resource folder of my app bundle.
  • I've switched on migrations by passing in a dictionary with the NSMigratePersistentStoresAutomaticallyOption key as [NSNumber numberWithBool:YES] when adding the Persistent Store.
  • Rather than merging all models in the bundle, I've specified the two models I want to use (model 1 and the new version of model 2) and merged them using modelByMergingModels:

问题

无论我做什么迁移,我都会收到错误消息:

No matter what I do to migrate, I get the error message:

持久存储迁移失败,缺少源托管对象模型."

"Persistent store migration failed, missing source managed object model."

我的尝试

  • 每次构建后我都会进行清理.
  • 我尝试了各种组合只有我要迁移的模型到资源中,正在编译,或两个都.
  • 由于错误信息表示找不到源我的迁移模型,我试过了拥有模型的每个版本资源文件夹和存在编译.
  • 我确定我不是犯了一个非常基本的错误切换回原来的我的数据模型的版本.该应用程序运行良好.
  • 我已删除映射型号及新版模型,清洁,然后重新创建两者.
  • 我尝试过做出不同的改变在新模型中 - 删除实体而是.

我束手无策.

我不禁认为我在某个我没有看到的地方犯了一个巨大的错误.有什么想法吗?

I can't help but think I've made a huge mistake somewhere that I'm not seeing. Any ideas?

推荐答案

两种可能:

  1. 您应用中的源模型与磁盘上的实际存储不匹配.
  2. 您的映射模型与您的源模型不匹配.

打开 Core Data 调试,您应该能够看到 Core Data 在进行迁移时正在寻找的哈希值.将这些哈希值与您存储在磁盘上的内容进行比较,看看它们是否匹配.同样,调试应该让您看到映射模型中的哈希值,以帮助您匹配所有内容.

Turn on Core Data debugging and you should be able to see the hashes that Core Data is looking for when it is doing the migration. Compare these hashes to what is in your store on disk and see if they match up. Likewise the debugging should let you see the hashes in the mapping model to help you match everything up.

如果只是您的映射模型未对齐,您可以告诉它从 Xcode 的设计菜单中从源代码更新.如果您缺少磁盘上存储文件的实际源模型,则可以查看版本控制系统或尝试使用自动迁移将该文件迁移到您认为是源的模型.

If it is just your mapping model that is misaligned, you can tell it to update from source from the design menu in Xcode. If you are missing the actual source model for your store file on disk then you can look in your version control system or try using an automatic migration to get that file to migrate to the model that you believe is the source.

更改源模型和目标模型的位置已移至编辑器窗口底部:

The location for changing the source and destination models has moved to the bottom of the editor window:

这篇关于核心数据迁移问题:“持久存储迁移失败,缺少源托管对象模型."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆