In the past, I have already successfully implemented automatic migration from version 1 of my data model to version 2. Now, using SDK 3.1.3, the transition from version 2 to version 3 ended with the following error:
Unresolved error Error Domain = NSCocoaErrorDomain Code = 134110 UserInfo = 0x5363360 "Operation could not be completed. (Cocoa error 134110.)", {NSUnderlyingError = Error Domain = NSCocoaErrorDomain Code = 256 UserInfo = 0x53622b0 "Operation could not be completed. 256.) "; reason = "Failed to save the new store after the first migration."; }
I tried automatic migration using NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption , as well as migration using only NSMigratePersistentStoresAutomaticallyOption , providing a mapping model from v2 to v3.
I see that the specified error is registered and there is no object in the application. However, if I exit the application and open it again, everything will be in place and will work.
The main data methods I use are as follows:
- (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } NSString *path = [[NSBundle mainBundle] pathForResource:@"MYAPP" ofType:@"momd"]; NSURL *momURL = [NSURL fileURLWithPath:path]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; return managedObjectModel; } - (NSManagedObjectContext *) managedObjectContext { if (managedObjectContext != nil) { return managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { managedObjectContext = [[NSManagedObjectContext alloc] init]; [managedObjectContext setPersistentStoreCoordinator: coordinator]; } return managedObjectContext; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP.sqlite"]]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
In the simulator, I see that this generates the MYAPP ~ .sqlite files and the MYAPP.sqlite file. I tried to delete the MYAPP ~ .sqlite file, but
BOOL oldExists = [[NSFileManager defaultManager] fileExistsAtPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP~.sqlite"]];
always returns NO. Any clue? Am I doing something wrong? Thank you in advance.