Alex Rivera | Logout

Can't find mapping model for migration - UIManagedDocument Core Data Migration

Asked 2012-10-08T13:16:29.817
13

I have two versions of my model Model001.xcdatamodel and Model002.xcdatamodel. These two are in the Model.xcdatamodeld bundle. I also have a Model001to002.xcmappingmodel which is not part of the Model.xcdatamodeld. I checked: both the xcmappingmodel and the xcdatamodeld get copied into the .app bundle.

My managed object context is initialized like this:

    NSURL *documentModel = [bundle URLForResource:@"Model" 
                                     withExtension:@"momd"]; managedObjectModel = [[NSManagedObjectModel alloc]
    initWithContentsOfURL:documentModel]; return managedObjectModel;

I also set these properties on my overridden initWithFileURL: in my UIManagedObject subclass.

    NSMutableDictionary *options = [NSMutableDictionary dictionaryWithDictionary:self.persistentStoreOptions];
    [options setObject:@YES forKey:NSMigratePersistentStoresAutomaticallyOption];
    [options setObject:@YES forKey:NSInferMappingModelAutomaticallyOption];
    self.persistentStoreOptions = [options copy];

But when I try to open a documet, I get the following error: Can't find mapping model for migration

-- UPDATE --

Even if I do a manual migration

     [NSMappingModel mappingModelFromBundles:@[[NSBundle mainBundle]]
                              forSourceModel:sourceObjectModel
                            destinationModel:self.managedObjectModel];

this returns nil. Although I double checked that the Model001to002.cdm is in the app bundle. It has to be in the app bundle right?

Edit
Report

1 Answer

28

A "gotcha" with mapping models is that you are not allowed to make any changes to the models after you created the mapping. If you do, you will also get this error.

answered 2013-02-01T13:19:53.737

Your Answer