简体   繁体   中英

Core Data Second Migration Before App Launch - Presented with Unresolved Error: Domain Error

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM