Core Data: Error, “Can’t Merge Models With Two Different Entities Named ‘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.

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! 🙂

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)