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

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

问题描述

背景

  • 一个 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天全站免登陆