涉及新实体和一对多关系的核心数据迁移
我正在尝试将一个新实体(例如 B,具有两个“双”属性)添加到我的核心数据模型中,并创建与现有实体(例如 A)的可选对多关系。我创建了新的模型修订版,其中包括新实体 B、现有实体 A 和一对多关系 A ->> B. 这个新模型是默认模型。我创建了一个从 v2 到 v3 的映射模型(v1 -> v2 迁移工作正常,只是实体 A 的数据类型更改),但没有指定 A 与 B 关系的值表达式,也没有指定 B 属性的值表达式。
当我运行应用程序时,尝试实例化托管对象模型 managementObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] keep];
时收到以下错误。
*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** -[NSMutableArray insertObject:atIndex:]: 尝试在 0 处插入 nil 对象”。
问题可能是我没有在映射模型中指定 A 与 B 关系的值表达式,但我认为没有必要,因为 B 是可选的,并且在模型的 v2 中不存在。如果我确实必须为关系指定一个值表达式,那么对于不存在的(因为它不存在于模型的 v2 中)可选关系,我该如何执行此操作?
非常感谢任何帮助。
PS - 还有一个问题 - 映射模型是否必要,或者自动迁移是否足够智能来处理新实体和关系?
I am attempting to add a new entity (say B, with two "double" attributes) to my core data model and create an optional to-many relationship with an existing entity (say A). I created the new model revision that includes the new entity B, the existing entity A, and a to-many relationship A ->> B. This new model is the default model. I created a mapping model from v2 to v3 (v1 -> v2 migration works fine, just data type changes for entity A), but did not specify a value expression for A's relationship to B, nor value expressions for B's attributes.
When I run the app, I receive the following error when attempting to instantiate the managed object model managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'.
The problem is probably that I did not specify a value expression for A's relationship to B in the mapping model, but I thought that its not necessary because B is optional and it did not exist in v2 of the model. If I do have to specify a value expression for relationship, how do I do so for a non-existent (as it doesn't exist in v2 of the model) optional relationship?
Any help is greatly appreciated.
PS - one more question - is a mapping model even necessary, or is automatic migration smart enought to to handle the new entity and the relationship?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚在自己的项目中解决了这个问题。当你有多个版本的数据模型时,[NSManagedObjectModel mergedModelFromBundles:nil] 表现不佳。它试图包含所有这些,但它不应该包含在内。
尝试使用类似这样的内容:
对于深入的故事检查:
http://iphonedevelopment.blogspot.com/2009/09/core -data-migration-problems.html
I just resolved this problem in my own project. [NSManagedObjectModel mergedModelFromBundles:nil] is not playing nice when you've multiple versions of your datamodel. It's trying to include all of them, and it shouldn't.
Try using something like this instead:
For the in depth story check:
http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html