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

只谈情不闲聊 提交于 2019-12-21 12:11:11

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/4011807/core-data-lightweight-migration-cant-find-or-automatically-infer-mapping-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!