• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Data merging
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data merging


  • Subject: Re: Core Data merging
  • From: Adam Swift <email@hidden>
  • Date: Wed, 20 Aug 2008 15:01:07 -0700



On Aug 15, 2008, at 5:26 AM, Vadim Lozko wrote:

On Aug 15, 2008, at 6:09 AM, Tim Isted wrote:

On 15 Aug 2008, at 00:19, Vadim Lozko wrote:

I'm having a problem trying to upgrade an existing store of a Core Data database to a newer model that simply has 1 additional attribute property in an entity. This is not a document based app. Also, not sure if this is significant, but the xcdatamodel and all related files are stored in a framework.

[...]

I tried to go about this two different ways. One was was to include only the newer model file and the mapping file to the build. However, the error I get is:
Error while adding persistent store: Error Domain=NSCocoaErrorDomain Code=134140 UserInfo=0x3c9030 "Persistent store migration failed, missing mapping model."

You do need to have the relevant data models inside your project, normally stored inside a datamodel bundle...

This is a good way to keep multiple versions of your data model organized in your project, but it isn't necessary to be able to use Core Data's store migration support.


However, when I include all three files (both model and the mapping), it seems like it's trying to merge the two and ignore the mapping file altogether. The error I get is:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'SomePrivateEntityName''

This particular problem is normally reasonably easy to fix.
Are you storing your data models in a data model bundle (filename.datamodeld)? You can then specify in Xcode which one is the current version. Assuming this is done, make sure that only one of your data models (the current version) has its target checkbox ticked, but don't tick any of the others. Sometimes you need to un- tick them all and re-tick them, or occasionally I've had to clean a project to get Xcode to accept and obey different ticks. If you have two data models (usually inside a bundle) included in the target and they have some or all of the same entity names inside, you will get this error if both models are being included in the target app.


It seems like your two responses contradict themselves. First, you want me to include all the relavent models. In your second response you want me to only include only the one model. I did specify that the models are part of a framework, so they wouldn't be part of the resources of the app. And if XCode had a physical interface, the clean button would have been worn out a long time ago. If I follow the steps to your second response, i'll go right back to the same error your first response was for. And yes, It is inside a datamodeld with one checked off as the current version. For the record, when I include only the newer datamodel, the error I get is:

Error while adding persistent store: Error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x34f0c0 "Persistent store migration failed, missing source managed object model."

If you want to use a model version bundle (xcdatamodeld) to group versions of your data model, then you need to write code to find the path for the source model, destination model and mapping model, then call the migration manager directly to perform the migration:


modelWrapper = [NSBundle bundleWithPath:[[NSBundle bundleForClass: [self class]] pathForResource:@"YourModelBundleName" ofType:@"momd"]];
sourceModelPath = [modelWrapper pathForResource:@"YourSourceModelName" ofType:@"mom"];
sourceModel = [[NSManagedObjectModel alloc] initWIthContentsOfURL: [NSURL fileURLWithPath: sourceModelPath];
destinationModelPath = [modelWrapper pathForResource:@"YourDestinationModelName" ofType:@"mom"];
destinationModel = [[NSManagedObjectModel alloc] initWIthContentsOfURL: [NSURL fileURLWithPath:destinationModelPath];
mappingModel = ... same idea ...


migrationManager= [[[NSMigrationManager alloc] initWithSourceModel:sourceModel destinationModel:destinationModel] autorelease];
[migrationManager migrateStoreFromURL:storeURL type:NSXMLStoreType options:nil withMappingModel:mappingModel toDestinationURL:newStoreURL destinationType:NSXMLStoreType destinationOptions:nil error:&error];



If you want to let Core Data do the work to find your data models and mapping models for migration, then you need to (a) make sure the models are exposed as top level resources and (b) specify the exact model you want to use rather than simply merging models via mergedModelFromBundles:


modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"YourModelName" ofType:@"mom"];
model = [[NSManagedObjectModel alloc] initWIthContentsOfURL:[NSURL fileURLWithPath:modelPath];


- adam

_______________________________________________

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


References: 
 >Core Data merging (From: Vadim Lozko <email@hidden>)
 >Re: Core Data merging (From: Tim Isted <email@hidden>)
 >Re: Core Data merging (From: Vadim Lozko <email@hidden>)

  • Prev by Date: [Q] SFPreferenceView and authorize as admin?
  • Next by Date: Control-Click vs Right-Click in NSTableView
  • Previous by thread: Re: Core Data merging
  • Next by thread: Re: Core Data merging
  • Index(es):
    • Date
    • Thread