views:

47

answers:

1

Hi Guys,

I need to add some attributes to my core data model and I am having a terrible time getting lightweight migration to work!

I keep getting the error "Cant merge models with two different entities named blah".

Here's what I've done ...

  1. Added this code to my app delegate.

    • (NSPersistentStoreCoordinator*)persistentStoreCoordinator {

      //blah blah

      NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
      [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
      [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

      //blah blah

      return _persistentStoreCoordinator;
      }

  2. Clicked on my data model, went to Design > Data Model > Add Model Version.

  3. Made my changes to the one with the LOWEST number, basically adding a few attributes.

  4. Deleted all the managed files produced from my previous model, sent them to trash, then created new ones from the new model.

  5. Cleaned all targets.

  6. Build and go.

ERROR.

Please please help. I've tried the above in numerous different ways, and loads of other stuff, each time going back to a clean copy of my project and starting again, and nothing has got me past this error.

Thanks!

+1  A: 

Well, once again, another 6 hours of my life completely wasted because Apple are a bunch of ... well, I'll stop there.

Anyway, thanks to this lovely person: http://linkroller.com/fullpage/ad/13754/?http://iphonedevelopment.blogspot.com/2009/09/core-data-migration-problems.html I was able to solve the problem.

You follow the steps I already followed, then you need to find the following method:

- (NSManagedObjectModel *)managedObjectModel {

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

    managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];    
    return managedObjectModel;
}

and change it to:

- (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 you xcdatamodeld file.

AAAAAARGH.

Steven