Core Data lightweight migration: Can't find or automatically infer mapping model for migration
Asked Answered
H

1

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!

Hanford answered 25/10, 2010 at 3:51 Comment(3)
Do you also have to specify a default value for the Attribute if you make it non-optional?Teal
I don't mind the neg. I mind not being told why. How lame.Teal
Ahh, probably because I answered your question in my description: "giving it a default value".Hanford
H
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.

Hegelian answered 27/10, 2010 at 23:23 Comment(2)
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?Reincarnate
@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.Hegelian

© 2022 - 2024 — McMap. All rights reserved.