核心数据:错误,“不能合并具有两个不同实体的模型命名为'foo'” [英] Core Data: Error, "Can't Merge Models With Two Different Entities Named 'foo' "

查看:171
本文介绍了核心数据:错误,“不能合并具有两个不同实体的模型命名为'foo'”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用Core Data的iPhone应用程式。大多数时候,我只是在模拟器测试,但偶尔将应用程序下载到iPad以确保。

I'm working on an iPhone app that uses Core Data. Most times, I just test in the simulator, but occasionally pump the app down to the iPad to make sure.

我最近更改了我的Core Data模型,现在当我把应用程序发送到iPad,我得到一个SIGABRT异常告诉我:

I've recently changed my Core Data model, and now when I send the app to the iPad, I get a SIGABRT exception telling me:

 Can't merge models with two different entities named 'foo'

好的,我明白了。设备上存在旧版本的数据库。所以,我(尝试)通过按/应用程序的图标杀死旧版本,直到它开始摆动,然后点击其X。 iPad会问我是否要删除应用程序及其所有数据。我说是的。

OK, that I understand. Old version of the database exists on the device. So, I (try to) kill the old version by press/holding the application's icon until it starts wiggling, and then tap its "X". The iPad asks me if I want to delete the application and all of its data. I say yes.

我重建应用程序,定位到iPad,并得到相同的错误。

I rebuild the app, targetting the iPad, and get the same error.

有没有让老数据库真正走开的窍门?

Is there a trick to getting the old database to really go away?

推荐答案

对于那些在尝试使用core数据轻量级迁移:

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

即使遵循了创建新版本数据模型的说明,我也遇到了此问题。我注意到,在我的应用程序包中有两个.mom文件,一个.mom和一个包含.mom文件的.momd目录。

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.

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

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; }

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

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! :)

这篇关于核心数据:错误,“不能合并具有两个不同实体的模型命名为'foo'”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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