Question

I'm encountering a very annoying error using Core Data on Mac OS X 10.5.

All entities have classes in my application which share the same names.

Up to this point, I've done 5 migrations without problems.

I'm using the XML data store. I've got V5 of my data model with 13 entities, 4 of which are abstract. It looks like this: alt text http://synapticmishap.co.uk/ObjectModel.jpg

What I do

  1. Create a new version of my data model - this is V6.

  2. Add a new entity (JGToolbarWindow) and set the parent to JGWindowBase.

  3. Added a mapping model that goes from V5 to V6. Saved it.

  4. Set the current version to be V6.

  5. Build and Debug.

I've got automatic migration switched on in the Persistent Store Coordinator options dictionary.

The Problem

  1. Get an error - "Multiple validation errors occurred."

  2. I've set a breakpoint and examined the validation errors. There's a long list of validation errors - there seems to be one for every data entry.

  3. It seems that it's stripping out ALL the relationships and since one of my properties - application - is set to be required, this counts as a validation error.

  4. So it seems the problem lies with the migration not being able to migrate the relationships... even though apparently nothing has changed as far as relationships go.

  5. When I look in ~/Library/Application Support/Name of my app/ I see an XML Data Store that's got the same name appended by .xml.new When looking at this file in a text editor, all the relationships have indeed been stripped out.

What I've tried

  1. Creating a new XML data store and putting a handful of items in it, then trying again. I get the same errors for each item.

  2. Cleaning and rebuilding.

  3. Making sure the old .xml.new from previous validation has been deleted.

  4. Deleting the new model version and repeating my actions to make sure I didn't screw something up.

  5. Adding mapping entries for each of the abstract classes, which are ignored by default. Added all attributes and relationships. Still exactly the same error.

  6. Tried adding a new entity that doesn't have a class, just based on NSManagedObject which has JGWindowBase as a parent. Again, failed.

The only thing I can think that has changed is some of my internal logic in the classes underlying the model. But these are minor changes and I can't understand how it was migrating fine, and now it's not when nothing appears to have changed.

I've tried a brand new migration from a renamed latest data store and have exactly the same problems. Which means I've got to solve this problem for any data migration to work.

Errors

When I put a breakpoint at the presentError line below

if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                                  configuration:nil 
                                                            URL:url 
                                                        options:options 
                                                          error:&error]){
          [[NSApplication sharedApplication] presentError:error];
}

and examine the error userInfo, I get lots of errors like this:

Error Domain=NSCocoaErrorDomain Code=1570 UserInfo=0x67ebfd0 "item is a required value."

po (NSArray *)0x67ebfd0

gives:

NSLocalizedDescription = "item is a required value.";
NSValidationErrorKey = item;
NSValidationErrorObject = <NSManagedObject: 0x45d5830> (entity: JGLogEntry; id: 0x4baccb0 <x-coredata://B597E13E-BE74-402E-BF00-5E1D57898406/JGLogEntry/p13942> ; data: {
duration = nil;
item = nil;                   // <<< Here's the problem.
processBundleID = nil;
processID = nil;
processName = nil;
startTime = 2009-10-09 16:41:44 +0100;
stopTime = 2009-10-09 16:42:17 +0100;
windowDocumentPathOrURL = nil;
windowID = nil;
windowTitle = nil;

All this really tells me is that it's removed the relationship connected to item, which is a required property which is why it's telling me there are validation errors. There are a whole load for application too, which is the other required property.

As I see it, the problem isn't with the validation errors as such, it's that it seems to be not migrating any relationships at all.

I'm pulling my hair out with this. I'd really, really appreciate some help. And finally, a Star Wars quote:

"Help me, Stack Overflow. You're my only hope."

Was it helpful?

Solution

Upgrade To Snow Leopard

Snow Leopard seems to address this issue - I've not had any problems with migrating data since the upgrade.

Alternatively, I suppose it may gone away because I switched to the SQLite data store, although I think it's more likely that migrations with abstract objects are a bit broken on Leopard.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top