Re: Core Data Migration Exception
Re: Core Data Migration Exception
- Subject: Re: Core Data Migration Exception
- From: Diederik Hoogenboom <email@hidden>
- Date: Wed, 2 Jan 2008 20:46:31 +0100
Hi Steve,
The problem might be that your old pre-Xcode 3 model doesn't have any
version metadata. The migration manager needs to know the versions of
both the models in order to apply the mapping. A possible solution is
to manually call
migrateStoreFromURL:type:options:withMappingModel:toDestinationURL:destinationType:destinationOptions:error
: in case the model doesn't have a version.
- Diederik
--
Diederik Hoogenboom
AIM: obviousmatter
Twitter: obviousmatter
Obvious Matter - DiskLibrary for Mac
http://www.obviousmatter.com
On 2 jan 2008, at 14:59, Steve Steinitz wrote:
Hello,
I would like to play with Core Data's new Leopard migration tools on a
application I've been developing over the past year. However, the
default migration code is throwing an exception.
The app was created in Xcode 2 but is now an Xcode 3, Leopard-only
project. I mention that in case there is anything special about
migrating older Core Data Models. I saw something to that effect on
another list but don't think that's my current issue.
Here are the steps to reproduce the exception. After reading the
Versioning and Migration Programming Guide I
1. used Xcode's Design menu to add a new model and then
2. added an new attribute to an entity.
3. I used the Design menu to create a Mapping Model.
4. In the code, I modified the default Model creation method,
-managedObjectModel, by adding
NSMigratePersistentStoresAutomaticallyOption YES
to the storeOptions dictionary argument of addPersistentStoreWithType
5. I further modified the -managedObjectModel code to avoid the error
'Can't merge models with two different entities named ...'
I now use NSManagedModel's -initWithContentsOfUrl to create the Model
rather than one of its more convenient model-merging class methods.
On
a side issue, that was fiddly to get right and remains fragile -- I
might put details in another thread.
Finally,
6. I used Xcode's Design menu to set the new, changed Model to be the
default Model then
7. cleaned, built and ran the app.
The app tried valiantly to start the migration but threw:
NSInternalInconsistencyException
Model already contains an entity named Bike.
(full trace below)
I don't think there is anything special about the Bike entity nor
was it
the one I changed -- its likely just the first one the migration
process
encountered.
Thanks for any guidance,
Steve
(Please don't include this trace in replies)
NSInternalInconsistencyException
Model already contains an entity named Bike.
1 -[NSManagedObjectModel(_NSManagedObjectModelPrivateMethods)
_addEntity:] (in CoreData)
2 -[NSManagedObjectModel setEntities:] (in CoreData)
3 -[NSManagedObjectModel copyWithZone:] (in CoreData)
4 -[NSObject copy] (in CoreFoundation)
5 +[NSManagedObjectModel modelByMergingModels:] (in CoreData)
6 +[NSManagedObjectModel
modelByMergingModels:forStoreMetadata:] (in CoreData)
7 +[NSManagedObjectModel
mergedModelFromBundles:forStoreMetadata:] (in CoreData)
8 -[NSStoreMigrationPolicy
sourceModelForStoreAtURL:metadata:error:] (in CoreData)
9 -[NSStoreMigrationPolicy(InternalMethods)
_gatherDataAndPerformMigration:] (in CoreData)
10 -[NSPersistentStoreCoordinator
addPersistentStoreWithType:configuration:URL:options:error:] (in
CoreData)
11 -[WWSalesReporting_AppDelegate persistentStoreCoordinator]
(in WWSales)
12 -[WWSalesReporting_AppDelegate managedObjectContext] (in
WWSales)
13 -[NSObject(NSKeyValueCoding) valueForKey:] (in Foundation)
14 -[NSObject(NSKeyValueCoding) valueForKeyPath:] (in Foundation)
15 -[NSBinder
_valueForKeyPath:ofObject:mode:raisesForNotApplicableKeys:] (in
AppKit)
16 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] (in
AppKit)
17 -[NSObjectParameterBinder
_updateObject:observedController:observedKeyPath:context:] (in AppKit)
18 -[NSObjectParameterBinder
_observeValueForKeyPath:ofObject:context:] (in AppKit)
19 -[NSBinder _performConnectionEstablishedRefresh] (in AppKit)
20 -[NSObject(NSKeyValueBindingCreation)
bind:toObject:withKeyPath:options:] (in AppKit)
21 -[NSNibBindingConnector establishConnection] (in AppKit)
22 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:]
(in AppKit)
23 loadNib (in AppKit)
24 +[NSBundle(NSNibLoading)
_loadNibFile:nameTable:withZone:ownerBundle:] (in AppKit)
25 +[NSBundle(NSNibLoading)
loadNibFile:externalNameTable:withZone:] (in AppKit)
26 +[NSBundle(NSNibLoading) loadNibNamed:owner:] (in AppKit)
27 -[WWSalesReporting_AppDelegate
applicationDidFinishLaunching:] (in WWSales)
28 _nsnote_callback (in Foundation)
29 __CFXNotificationPost (in CoreFoundation)
30 _CFXNotificationPostNotification (in CoreFoundation)
31 -[NSNotificationCenter postNotificationName:object:userInfo:]
(in Foundation)
32 -[NSNotificationCenter postNotificationName:object:] (in
Foundation)
33 -[NSApplication _postDidFinishNotification] (in AppKit)
34 -[NSApplication _sendFinishLaunchingNotification] (in AppKit)
35 -[NSApplication(NSAppleEventHandling) _handleAEOpen:] (in
AppKit)
36 -[NSApplication(NSAppleEventHandling)
_handleCoreEvent:withReplyEvent:] (in AppKit)
37 -[NSAppleEventManager
dispatchRawAppleEvent:withRawReply:handlerRefCon:] (in Foundation)
38 _NSAppleEventManagerGenericHandler (in Foundation)
39 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long,
unsigned char*) (in AE)
40 dispatchEventAndSendReply(AEDesc const*, AEDesc*) (i
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden