0

I am fairly new to Core Data and have only released version 1.0 and 1.1.1 of my App onto the App Store.

While starting to develop 1.2.0, I went through the Core Data lightweight migration successfully to create a new model. Everything was working. I recently discovered an issue with one of my entities and I had to therefore change an attribute from NSDate to NSString. With this in mind, I went through the migration again and called it 1.2.x. That's selected as the current version but when I run my app, I get:

Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 "The operation couldn’t be completed (Cocoa error 134140.)" UserInfo=0x1702e1380 {sourceModel=(<NSManagedObjectModel: 0x170086450>) isEditable 1, entities 

{Date = "(<NSEntityDescription: 0x17014d9f0>) name Date, managedObjectClassName Date, renamingIdentifier Date, isAbstract 0, superentity name (null), properties {\n    dateOfEvent = \"(<NSAttributeDescription: 0x170104c80>), name dateOfEvent, isOptional 1, isTransient 0, entity Date, renamingIdentifier dateOfEvent, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n    transactions = \"(<NSRelationshipDescription: 0x17014daa0>), name transactions, isOptional 1, isTransient 0, entity Date, renamingIdentifier transactions, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Transaction, inverseRelationship dates, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null)";

Years = "(<NSEntityDescription: 0x17014e020>) name Years, managedObjectClassName Years, renamingIdentifier Years, isAbstract 0, superentity name (null), properties {\n    transactions = \"(<NSRelationshipDescription: 0x17014e0d0>), name transactions, isOptional 1, isTransient 0, entity Years, renamingIdentifier transactions, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Transaction, inverseRelationship years, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\";\n    yearOfEvent = \"(<NSAttributeDescription: 0x170300510>), name yearOfEvent, isOptional 1, isTransient 0, entity Years, renamingIdentifier yearOfEvent, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null)";
    }, fetch request templates {
    }, destinationModel=(<NSManagedObjectModel: 0x17008a550>) isEditable 0, entities

Transaction = "(<NSEntityDescription: 0x17014c8c0>) name Transaction, managedObjectClassName Transaction, renamingIdentifier Transaction, isAbstract 0, superentity name (null), properties {\n    dates = \"(<NSRelationshipDescription: 0x17014c080>), name dates, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier dates, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Date, inverseRelationship transactions, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n    item = \"(<NSRelationshipDescription: 0x17014c130>), name item, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier item, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Item, inverseRelationship type, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n    notes = \"(<NSAttributeDescription: 0x17011dbe0>), name notes, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier notes, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n    occasion = \"(<NSRelationshipDescription: 0x17014c1e0>), name occasion, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier occasion, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Occasion, inverseRelationship categories, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n    subevent = \"(<NSRelationshipDescription: 0x17014c290>), name subevent, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier subevent, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Subevent, inverseRelationship categories, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n    wasReceived = \"(<NSAttributeDescription: 0x17011dc70>), name wasReceived, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier wasReceived, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n    whoBy = \"(<NSRelationshipDescription: 0x17014c340>), name whoBy, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier whoBy, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Person, inverseRelationship transactions, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n    years = \"(<NSRelationshipDescription: 0x17014c3f0>), name years, isOptional 1, isTransient 0, entity Transaction, renamingIdentifier years, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Years, inverseRelationship transactions, minCount 0, maxCount 1, isOrdered 0, deleteRule 1\";\n}, subentities (null), userInfo {\n}, versionHashModifier (null)";

The app doesn't run with this error. I have gone through and changed all of the NSDate to NSString but it seems worrying to me that this error is occurring because it's still not working.

I obviously cannot have my users uninstall and reinstall the app (that works with Xcode); is there anything I can do to get this working without having users to reinstall? Why isn't Core Data lightweight migration working?

Update I have two questions:

1) Because I am only changing the data type of an attribute, do I need to do a Lightweight Migration to another version or can I just change the attribute data type for the new version of the model that was previously created?

2) I have the code below in my app and a breakpoint exception is getting called with the error above at the abort code:

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    //abort();

If I comment this out, like I have above, the app works, but the errors output at the top of this question are still there. Also, more importantly, the data does NOT migrate. How safe is this? This makes me feel nervous about shipping my application with these issues.

tshepang
  • 12,111
  • 21
  • 91
  • 136
amitsbajaj
  • 1,304
  • 1
  • 24
  • 59
  • If you're getting a lot of other errors, it would be good to include them as well. The error you included doesn't say much. – Tom Harrington Apr 14 '14 at 22:03
  • Thanks Tom - this is in response to your other brilliant answer - I'm trying to work through those. I'm sorry the formatting is a bit messed up but I've now updated the error. Also I've updated the fact that I'm converting from an NSDate to an NSString and get this error. I suspect I should be using an NSNumber (Integer though) for the date conversion – amitsbajaj Apr 14 '14 at 22:12
  • Any thoughts on this error Tom? – amitsbajaj Apr 15 '14 at 05:53
  • I have updated the question with a few observations @TomHarrington – amitsbajaj Apr 15 '14 at 06:59

1 Answers1

1

You have to convert the NSDate value to an NSString. It's not enough to just change the type. If you are already doing this it's not clear from your question. The specific error you are getting is NSMigrationMissingMappingModelError, defined in CoreDataErrors.h . Core Data does not know how to go from an NSDate to an NSString. You must provide a means of mapping from one to the other.

quellish
  • 21,123
  • 4
  • 76
  • 83
  • Thanks Quelish - this is actually making sense. I deleted the branch that I used to try this out and in a new branch, I deleted the entity and re-created it with an NSString but still getting the same errors which is making sense that I need to convert it. I have gone through some of the code to change from an NSDate to an NSString but I'm still getting the errors - where would I do this conversion because the breakpoint is crashing at the abort line.. and so I can't find a line that needs to be converted – amitsbajaj Apr 15 '14 at 07:54
  • You will need to do the migration yourself. This is not something lightweight migration can do for you. See: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmCustomizing.html#//apple_ref/doc/uid/TP40004399-CH8-SW1 and https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmMappingOverview.html#//apple_ref/doc/uid/TP40004399-CH5-SW1 – quellish Apr 15 '14 at 07:57
  • Thanks so much @quellish - that's very helpful. I've managed to eradicate this error with the use of the manual migration; I do however have a problem with the migration working correctly but rather than clutter and make this question more confusing, I've created a new question: http://stackoverflow.com/questions/23080608/conversion-from-nsdate-to-nsstring-with-core-data-migration-on-attribute-not-dis - many thanks for your help with this one – amitsbajaj Apr 15 '14 at 10:08