无法解决,“无法合并具有两个不同实体的模型”

发布于 2024-09-28 02:35:27 字数 653 浏览 1 评论 0原文

我正在处理 iOS 4.1 中的核心数据项目(针对 3.1)。当我添加数据模型版本时,我收到可怕的“无法合并具有两个名为 xxx 的不同实体的模型”错误。“清理目标没有帮助。删除构建目录没有帮助。解决问题的唯一方法是删除以前安装的应用程序版本并安装新版本,这违背了版本控制和数据迁移的整个目的,

我有另一个项目成功地使用了此过程,并且它们共享我为处理核心数据而放在一起的相同代码库。我无法弄清楚是什么导致了这个项目的挂起。

我的核心数据代码基于 Grouchal 对此的回答 链接文本 和 Jeff Lamarche 的 链接文本。在故障排除中,我详细介绍了这些以及其他类似的文章在网上。大多数遇到此问题的人似乎都对“清理所有目标”很幸运。但我要出局了。

有什么建议吗?

I'm working with a Core Data project in iOS 4.1 (targeting 3.1). When I add a Data Model version I get the dreaded "Can't merge models with two different entities named xxx" error." Cleaning Targets does not help. Deleting the build directory does not help. The only thing that solves the issue is deleting the previously installed version of the app and installing fresh, which defeats the entire purpose of versioning and data migration.

I've got another project that's successfully using this process and they share the same code libraries I've put together for handling Core Data. I cannot figure out what could be hanging up the one project.

I based my Core Data code on, Grouchal's answer on this link text and Jeff Lamarche's link text. In troubleshooting I've poured over these as well as other, similar articles on the net. Most people with this issue seem to have had good luck with "Clean All Targets." But I'm striking out.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

弱骨蛰伏 2024-10-05 02:35:27

对于那些尝试使用核心数据轻量级迁移后遇到此问题的人:

即使按照创建数据模型新版本的说明进行操作,我仍然遇到此问题。我注意到我的应用程序包中有两个“.mom”文件,一个“.mom”和一个包含“.mom”文件的“.momd”目录。

基于此,我找到了这篇优秀的文章 解释问题并提供解决方案。

关键是用此实现替换为您生成的 - (NSManagedObjectModel *)managedObjectModel 的实现:

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
        return managedObjectModel;
    }

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Foo" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

    return managedObjectModel; }

其中“Foo”是您的数据模型的名称。

希望这对某人有用 - 我花了太多时间在这上面用头撞墙。再次感谢苹果! :)

For those who come across this question after trying to use core data lightweight migrations:

I was having this issue even after following the instructions for creating a new version of my data model. I noticed that there were two ".mom" files in my application bundle, one ".mom" and one ".momd" directory that contained ".mom" files.

Based on that, I was able to find this excellent post explaining the issue and offering a solution.

The key is to replace the implementation of - (NSManagedObjectModel *)managedObjectModel that is generated for you with this implementation:

- (NSManagedObjectModel *)managedObjectModel {

    if (managedObjectModel != nil) {
        return managedObjectModel;
    }

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Foo" ofType:@"momd"];
    NSURL *momURL = [NSURL fileURLWithPath:path];
    managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

    return managedObjectModel; }

where 'Foo' is the name of your data model.

Hopefully this is useful to someone - I spent WAY too many hours beating my head against the wall on this. Thanks again, Apple! :)

你在看孤独的风景 2024-10-05 02:35:27

这是我的解决方案

((RootViewController *) [self.tabBarController.viewControllers objectAtIndex:0]).managedObjectContext = self.managedObjectContext;
((AlbumViewController *) [self.tabBarController.viewControllers objectAtIndex:1]).managedObjectContext = self.managedObjectContext;
((CameraViewController *) [self.tabBarController.viewControllers objectAtIndex:2]).managedObjectContext = self.managedObjectContext;
((VideoViewController *) [self.tabBarController.viewControllers objectAtIndex:3]).managedObjectContext = self.managedObjectContext;

Here's my solution

((RootViewController *) [self.tabBarController.viewControllers objectAtIndex:0]).managedObjectContext = self.managedObjectContext;
((AlbumViewController *) [self.tabBarController.viewControllers objectAtIndex:1]).managedObjectContext = self.managedObjectContext;
((CameraViewController *) [self.tabBarController.viewControllers objectAtIndex:2]).managedObjectContext = self.managedObjectContext;
((VideoViewController *) [self.tabBarController.viewControllers objectAtIndex:3]).managedObjectContext = self.managedObjectContext;
妥活 2024-10-05 02:35:27

我发现我使用的第 3 方库正在创建自己的 CoreData 数据存储,并使用“合并模型”方法或数据模型管理。
我联系了供应商并帮助解决了这个问题。

I discovered that a 3rd party library I was using was creating it's own CoreData data store and was using the "merge models" method or data model management.
I contacted the vendor and the helpfully fixed the situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文