8

So I created a new version of my data model, and made a previously optional field non-optional (giving it a default value). According to the documentation, this should mean my migration is eligible for lightweight, automatic migration.

I also added options that allow this when I open the store, also per the documentation:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:

[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,

[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

When my app is starting, however, I get the following error:

"Can't find or automatically infer mapping model for migration".

Does anyone know what the problem here could be? Any help is appreciated... thanks!

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
elsurudo
  • 3,579
  • 2
  • 31
  • 48

1 Answers1

2

You've probably looked at this, but if not ... Detecting a Lightweight Core Data Migration

In terms of other debugging code, I found this helpful:

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MyDataStore.sqlite"]];

NSError *error = nil;
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeUrl error:&error];

if (!sourceMetadata)
{
    DLog(@"sourceMetadata is nil");
}
else
{
    DLog(@"sourceMetadata is %@", sourceMetadata);
}

And finally, this is kind of a pain but in the Finder you can "Show Package Contents" for your app and then find a folder called .momd and within that is a file called 'VersionInfo.plist'. This has been helpful in identifying what you have and where you're trying to go.

And finally, you could try to create a mapping model and see if that works. I've wrestled with migration issues for weeks, hence the long list of desperate debugging attempts.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
westsider
  • 4,967
  • 5
  • 36
  • 51
  • I have just started with iPhone development and I have run into this problem. I tried your code and it displays some value of `sourceMetadata`. How can I use this to debug the problem I am having? – vikmalhotra Jan 20 '11 at 09:22
  • @ShiVik - that would depend on the problem you are debugging ;-) If you post a question, I will try to help. Generally, though, this was helpful for assuring me that the right models were in use and had not been inadvertently corrupted. It also helped my overall understanding of Core Data. – westsider Jan 20 '11 at 10:07