I'm working on a manual migration, primarily using this stackoverflow answer as a guide: https://stackoverflow.com/a/8155531/5416
I have 3 separate entities that need to be migrated. Only one property on each is changing, and it's changing from an integer to a string. Some of the entities seem to go through just fine, and no exceptions are being thrown, but the process is not completing. It lists a bunch of errors that are all essentially exactly the same:
Error Domain=NSCocoaErrorDomain Code=1570 \"The operation couldn\U2019t be completed. (Cocoa error 1570.)\" UserInfo=0x2a4c2790 {NSValidationErrorObject=NSManagedObject_CCRecipeIngredient_2:, NSValidationErrorKey=name, NSLocalizedDescription=The operation couldn\U2019t be completed. (Cocoa error 1570.)}
Any ideas how best to troubleshoot this? If it helps, here's the migration policy that I'm using:
- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)aSource
entityMapping:(NSEntityMapping *)mapping
manager:(NSMigrationManager *)migrationManager
error:(NSError **)error {
NSString *attributeName = @"foodId";
NSEntityDescription *aSourceEntityDescription = [aSource entity];
NSString *aSourceName = [aSourceEntityDescription valueForKey:@"name"];
NSManagedObjectContext *destinationMOC = [migrationManager destinationContext];
NSManagedObject *destEntity;
NSString *destEntityName = [mapping destinationEntityName];
if ([aSourceName isEqualToString:@"CCFood"] || [aSourceName isEqualToString:@"CCFoodLogEntry"] || [aSourceName isEqualToString:@"CCRecipeIngredient"] )
{
destEntity = [NSEntityDescription
insertNewObjectForEntityForName:destEntityName
inManagedObjectContext:destinationMOC];
// attribute foodid
NSNumber *sourceFoodID = [aSource valueForKey:attributeName];
if (!sourceFoodID)
{
[destEntity setValue:@"0" forKey:attributeName];
}
else
{
NSInteger sourceFoodIDInteger = [sourceFoodID intValue];
NSString *sourceFoodIDString = [NSString stringWithFormat:@"%i", sourceFoodIDInteger];
[destEntity setValue:sourceFoodIDString forKey:attributeName];
}
[migrationManager associateSourceInstance:aSource
withDestinationInstance:destEntity
forEntityMapping:mapping];
return YES;
} else
{
// don't remap any other entities
return NO;
}
}