small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
05 May 2011, 23:15
Duncan Groenewald (12 posts)

Anyone got any idea what this error is all about. The app seems to run fine but now I am trying to upgrade the datamodel and the migration fails with the error below. This seems a bit odd because it seems to have nothing to do with any of the changes I made to the data model. Also if I remove the changes and migrate then it works fine. The changes were modifications to make a one-to-one relationship a one-to-many relationship.

How could I end up with different contexts ? Why does this only throw an error when migrating. The app runs just fine normally.

Any help would be appreciated - in the meantime I am going to try some other kinds of changes to the datamodel to see if I can get any migrations to work.

2011-05-06 09:09:20.454 iProject[30003:903] HIToolbox: ignoring exception ‘Illegal attempt to establish a relationship ‘parent’ between objects in different contexts (source = <NSManagedObject: 0x117f52220> (entity: PBSLeaf; id: 0x118f78be0 <x-coredata:///PBSLeaf/t512B9F7A-F523-420F-8EED-8E0BC6384E5D113> ; data: { children = ( ); details = nil; displayName = “Trading & Forecasting Information”; endDate = “2011-03-22 12:00:00 +1100”; isLeaf = 1; isSelectable = 1; parent = nil; responsiblePerson = nil; sortIndex = 0; startDate = “2011-03-21 12:00:00 +1100”; status = 0; }) , destination = <NSManagedObject: 0x117f71ac0> (entity: PBSGroup; id: 0x11907e790 <x-coredata://AE106281-80E4-4D4D-9D37-3FEB9D8E7527/PBSGroup/p152> ; data: ))' that raised inside Carbon event dispatch ( 0 CoreFoundation 0x00007fff808037b4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00007fff881bf0f3 objc_exception_throw + 45 2 CoreData 0x00007fff8395df65 _PFManagedObject_coerceValueForKeyWithDescription + 2037 3 CoreData 0x00007fff8397218e _sharedIMPL_setvfk_core + 158 4 CoreData 0x00007fff8395d638 -[NSManagedObject(_PFDynamicAccessorsAndPropertySupport) _setGenericValue:forKey:withIndex:flags:] + 24 5 CoreData 0x00007fff83972040 _PF_Handler_Public_SetProperty + 64 6 CoreData 0x00007fff83971f85 -[NSManagedObject setValue:forKey:] + 117 7 iProject 0x0000000100010cb4 -[LeafMigrationClass createDestinationInstancesForSourceInstance:entityMapping:manager:error:] + 804 8 CoreData 0x00007fff839f7875 -[NSMigrationManager(InternalMethods) _doFirstPassForMapping:error:] + 549 9 CoreData 0x00007fff839f68a0 -[NSMigrationManager migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error:] + 1504 10 CoreData 0x00007fff839f1ab3 -[NSStoreMigrationPolicy(InternalMethods) migrateStoreAtURL:toURL:storeType:options:withManager:error:] + 147 11 CoreData 0x00007fff839f18ca -[NSStoreMigrationPolicy migrateStoreAtURL:withManager:metadata:options:error:] + 106 12 CoreData 0x00007fff839f27cc -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 1116 13 CoreData 0x00007fff8393363d -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 1997 14 AppKit 0x00007fff84085101 -[NSPersistentDocument configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:] + 255 15 iProject 0x0000000100001d48 -[iProjectDoc configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:] + 360 16 AppKit 0x00007fff843028f6 -[NSPersistentDocument(NSDeprecatedInternal) _configurePersistentStoreCoordinatorForURL:ofType:error:] + 183 17 AppKit 0x00007fff84084d2c -[NSPersistentDocument readFromURL:ofType:error:] + 124 18 AppKit 0x00007fff83f5788e -[NSDocument initWithContentsOfURL:ofType:error:] + 265 19 AppKit 0x00007fff83f63108 -[NSDocumentController makeDocumentWithContentsOfURL:ofType:error:] + 332 20 AppKit 0x00007fff83f62ef8 -[NSDocumentController openDocumentWithContentsOfURL:display:error:] + 734 21 AppKit 0x00007fff83f625f2 -[NSDocumentController _openDocumentsWithContentsOfURLs:display:presentErrors:] + 3457 22 AppKit 0x00007fff83d7fe9a -[NSApplication sendAction:to:from:] + 95 23 AppKit 0x00007fff83da441e -[NSMenuItem _corePerformAction] + 365 24 AppKit 0x00007fff83da4188 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121 25 AppKit 0x00007fff84028279 -[NSMenu _internalPerformActionForItemAtIndex:] + 35 26 AppKit 0x00007fff83ed9f77 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136 27 AppKit 0x00007fff83d8695c NSSLMMenuEventHandler + 321 28 HIToolbox 0x00007fff858d27f7 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002 29 HIToolbox 0x00007fff858d1d46 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395 30 HIToolbox 0x00007fff858efa81 SendEventToEventTarget + 45 31 HIToolbox 0x00007fff8591ec35 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387 32 HIToolbox 0x00007fff8594ba0a SendMenuCommandWithContextAndModifiers + 56 33 HIToolbox 0x00007fff8594b9c2 SendMenuItemSelectedEvent + 101 34 HIToolbox 0x00007fff8594b8d2 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150 35 HIToolbox 0x00007fff8592cc27 _ZL14MenuSelectCoreP8MenuData5PointdjPP13OpaqueMenuRefPt + 467 36 HIToolbox 0x00007fff8592c37c _HandleMenuSelection2 + 453 37 AppKit 0x00007fff83c577dd _NSHandleCarbonMenuEvent + 236 38 AppKit 0x00007fff83c2b317 _DPSNextEvent + 1921 39 AppKit 0x00007fff83c2a7a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155 40 AppKit 0x00007fff83bf048b -[NSApplication run] + 395 41 AppKit 0x00007fff83be91a8 NSApplicationMain + 364 42 iProject 0x0000000100001ae2 main + 34 43 iProject 0x0000000100001ab4 start + 52 44 ??? 0x0000000000000003 0x0 + 3 )

Generic-user-small
06 May 2011, 04:43
Duncan Groenewald (12 posts)

By the way the migration has worked just fine in the past so unless I inadvertently made some changes somewhere to something its unclear why it should not suddenly fail. I have tried using a fresh set of data but get the same error. Complaint seems to be about the parent/child relationships in a hierarchy.

Here is the custom migration code (yes its worked fine in the past)

  • (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { NSLog(@”GroupMigrationClass createDestinationInstances called for %@”, [sInstance valueForKey:@”displayName”]);

    NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager destinationContext]];

    [newObject setValue:[sInstance valueForKey:@”details”] forKey:@”details”]; [newObject setValue:[sInstance valueForKey:@”displayName”] forKey:@”displayName”]; [newObject setValue:[sInstance valueForKey:@”endDate”] forKey:@”endDate”]; [newObject setValue:[sInstance valueForKey:@”isLeaf”] forKey:@”isLeaf”]; [newObject setValue:[sInstance valueForKey:@”isSelectable”] forKey:@”isSelectable”]; [newObject setValue:[sInstance valueForKey:@”sortIndex”] forKey:@”sortIndex”]; [newObject setValue:[sInstance valueForKey:@”startDate”] forKey:@”startDate”]; [newObject setValue:[sInstance valueForKey:@”status”] forKey:@”status”];

    NSLog(@”GroupMigrationClass createDestinationInstances Step 1”);

    [newObject setValue:[sInstance valueForKey:@”parent”] forKey:@”parent”]; [newObject setValue:[sInstance valueForKey:@”children”] forKey:@”children”]; [newObject setValue:[sInstance valueForKey:@”responsiblePerson”] forKey:@”responsiblePerson”];

    [newObject setValue:[sInstance valueForKey:@”canCollapse”] forKey:@”canCollapse”]; [newObject setValue:[sInstance valueForKey:@”canExpand”] forKey:@”canExpand”]; [newObject setValue:[sInstance valueForKey:@”isExpanded”] forKey:@”isExpanded”]; [newObject setValue:[sInstance valueForKey:@”isSpecialGroup”] forKey:@”isSpecialGroup”];

    NSLog(@”GroupMigrationClass createDestinationInstances Step 2”);

    [manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping];

    return YES; }

Avatarsmall_pragsmall
11 Dec 2011, 20:33
Marcus S. Zarra (284 posts)

That error indicates that you have entities created in more than one context and you are trying to create a relationship between them.

Consider each @NSManagedObjectContext@ to be its own sandbox. Any @NSManagedObject@ created in one sandbox cannot be connected with a @NSManagedObject@ created in another.

I would suggest adding a breakpoint, printing out the pointer to each @NSManagedObjectContext@ for those @NSManagedObject@ instances and then track them down.

You must be logged in to comment