in my app I've used Core Data Automatic Lightweight Migration fine for multiple versions. About a year ago I implemented iOS File Sharing so I moved the sqlite database to the /Library folder rather than the /Documents directory to keep it hidden. I haven't added another Core Data version since that time.
Now when I try to add another Entity and increase the model version I get the following error (truncated to show just the tail end):
"_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}
Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason:
'This NSPersistentStoreCoordinator has no persistent stores.
It cannot perform a save operation.'
I've verified that the .sqlite file exists on disk as expected. I've been troubleshooting for a few days and it seems if I move the sqlite file back to the /Documents directory the migration works OK.
Below is the code for the persistent store coordinator:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self libraryDocumentsDirectory] stringByAppendingPathComponent: @"myappdb.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
//Pass options in for lightweight migration....
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:options error:&error]) {
/*Error for store creation should be handled in here*/
NSLog(@"ERROR IN MIGRATION........%@", error);
}
return persistentStoreCoordinator;
}
- (NSString *)libraryDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
}
Has anyone encountered this situation before?
Thanks in advance for your help.