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

查看:20
本文介绍了核心数据:错误,“无法合并具有名为 '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?

推荐答案

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

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.

关键是用这个实现替换为你生成的- (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天全站免登陆