Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I seeing this error when changing a Core Data attribute from Integer 16 to String?

Tags:

ios

core-data

I have a Core Data model that has one attribute currently set as an Integer 16. I'm now wanting to change the attributes name and change its type, but keep the current data. I've got the name change sorted, and it's running without problem.

Upon trying to change the data type I get the following really long error, what can I do to solve it?

2012-07-10 19:33:06.298 Medicine Tracker[5170:707] Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 "The operation couldn’t be completed. (Cocoa error 134140.)" UserInfo=0x2ae140 {reason=Can't find or automatically infer mapping model for migration, destinationModel=(<NSManagedObjectModel: 0xf694e20>) isEditable 0, entities {
Log = "(<NSEntityDescription: 0xf6947b0>) name Log, managedObjectClassName Log, renamingIdentifier Log, isAbstract 0, superentity name (null), properties {\n    date = \"(<NSAttributeDescription: 0xf6941d0>), name date, isOptional 1, isTransient 0, entity Log, renamingIdentifier date, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n    medicine = \"(<NSRelationshipDescription: 0xf694410>), name medicine, isOptional 1, isTransient 0, entity Log, renamingIdentifier medicine, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Medicine, inverseRelationship logs, minCount 1, maxCount 1, isOrdered 0, deleteRule 1\";\n    note = \"(<NSAttributeDescription: 0xf694220>), name note, isOptional 1, isTransient 0, entity Log, renamingIdentifier note, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities (null), userInfo {\n}, versionHashModifier (null)";
Medicine = "(<NSEntityDescription: 0xf694810>) name Medicine, managedObjectClassName Medicine, renamingIdentifier Medicine, isAbstract 0, superentity name (null), properties {\n    active = \"(<NSAttributeDescription: 0xf694270>), name active, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier active, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n    dose = \"(<NSAttributeDescription: 0xf6942c0>), name dose, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier amountToTake, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n    hoursBetween = \"(<NSAttributeDescription: 0xf694310>), name hoursBetween, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier hoursBetween, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\";\n    logs = \"(<NSRelationshipDescription: 0xf694470>), name logs, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier logs, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Log, inverseRelationship medicine, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\";\n    name = \"(<NSAttributeDescription: 0xf694360>), name name, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier name, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n    \\\"com.apple.syncservices.Syncable\\\" = NO;\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities (null), userInfo {\n    \"com.apple.syncservices.Syncable\" = NO;\n}, versionHashModifier (null)"; }, fetch request templates { }, sourceModel=(<NSManagedObjectModel: 0x2adbb0>) isEditable 1, entities {
Log = "(<NSEntityDescription: 0x2ac700>) name Log, managedObjectClassName Log, renamingIdentifier Log, isAbstract 0, superentity name (null), properties {\n    date = \"(<NSAttributeDescription: 0x294ac0>), name date, isOptional 1, isTransient 0, entity Log, renamingIdentifier date, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\";\n    medicine = \"(<NSRelationshipDescription: 0x294a60>), name medicine, isOptional 1, isTransient 0, entity Log, renamingIdentifier medicine, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Medicine, inverseRelationship logs, minCount 1, maxCount 1, isOrdered 0, deleteRule 1\";\n    note = \"(<NSAttributeDescription: 0x2ac810>), name note, isOptional 1, isTransient 0, entity Log, renamingIdentifier note, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n}, versionHashModifier (null)";
Medicine = "(<NSEntityDescription: 0x294b10>) name Medicine, managedObjectClassName Medicine, renamingIdentifier Medicine, isAbstract 0, superentity name (null), properties {\n    active = \"(<NSAttributeDescription: 0x2adaa0>), name active, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier active, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\";\n    dose = \"(<NSAttributeDescription: 0x2adaf0>), name dose, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier amountToTake, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\";\n    hoursBetween = \"(<NSAttributeDescription: 0x2adb40>), name hoursBetween, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier hoursBetween, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\";\n    logs = \"(<NSRelationshipDescription: 0x2ada40>), name logs, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier logs, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n}, destination entity Log, inverseRelationship medicine, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\";\n    name = \"(<NSAttributeDescription: 0x2ad9f0>), name name, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier name, validation predicates (\\n), warnings (\\n), versionHashModifier (null)\\n userInfo {\\n    \\\"com.apple.syncservices.Syncable\\\" = NO;\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\";\n}, subentities {\n}, userInfo {\n    \"com.apple.syncservices.Syncable\" = NO;\n}, versionHashModifier (null)"; }, fetch request templates { }, NSUnderlyingError=0x2b0140 "The operation couldn’t be completed. (Cocoa error 134190.)"}, {
NSUnderlyingError = "Error Domain=NSCocoaErrorDomain Code=134190 \"The operation couldn\U2019t be completed. (Cocoa error 134190.)\" UserInfo=0x2b0160 {reason=Source and destination attribute types are incompatible, entity=Medicine, property=dose}";
destinationModel = "(<NSManagedObjectModel: 0xf694e20>) isEditable 0, entities {\n    Log = \"(<NSEntityDescription: 0xf6947b0>) name Log, managedObjectClassName Log, renamingIdentifier Log, isAbstract 0, superentity name (null), properties {\\n    date = \\\"(<NSAttributeDescription: 0xf6941d0>), name date, isOptional 1, isTransient 0, entity Log, renamingIdentifier date, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\\\";\\n    medicine = \\\"(<NSRelationshipDescription: 0xf694410>), name medicine, isOptional 1, isTransient 0, entity Log, renamingIdentifier medicine, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, destination entity Medicine, inverseRelationship logs, minCount 1, maxCount 1, isOrdered 0, deleteRule 1\\\";\\n    note = \\\"(<NSAttributeDescription: 0xf694220>), name note, isOptional 1, isTransient 0, entity Log, renamingIdentifier note, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\\\";\\n}, subentities (null), userInfo {\\n}, versionHashModifier (null)\";\n    Medicine = \"(<NSEntityDescription: 0xf694810>) name Medicine, managedObjectClassName Medicine, renamingIdentifier Medicine, isAbstract 0, superentity name (null), properties {\\n    active = \\\"(<NSAttributeDescription: 0xf694270>), name active, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier active, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\\\";\\n    dose = \\\"(<NSAttributeDescription: 0xf6942c0>), name dose, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier amountToTake, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\\\";\\n    hoursBetween = \\\"(<NSAttributeDescription: 0xf694310>), name hoursBetween, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier hoursBetween, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\\\";\\n    logs = \\\"(<NSRelationshipDescription: 0xf694470>), name logs, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier logs, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, destination entity Log, inverseRelationship medicine, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\\\";\\n    name = \\\"(<NSAttributeDescription: 0xf694360>), name name, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier name, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n    \\\\\\\"com.apple.syncservices.Syncable\\\\\\\" = NO;\\\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\\\";\\n}, subentities (null), userInfo {\\n    \\\"com.apple.syncservices.Syncable\\\" = NO;\\n}, versionHashModifier (null)\";\n}, fetch request templates {\n}";
reason = "Can't find or automatically infer mapping model for migration";
sourceModel = "(<NSManagedObjectModel: 0x2adbb0>) isEditable 1, entities {\n    Log = \"(<NSEntityDescription: 0x2ac700>) name Log, managedObjectClassName Log, renamingIdentifier Log, isAbstract 0, superentity name (null), properties {\\n    date = \\\"(<NSAttributeDescription: 0x294ac0>), name date, isOptional 1, isTransient 0, entity Log, renamingIdentifier date, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 900 , attributeValueClassName NSDate, defaultValue (null)\\\";\\n    medicine = \\\"(<NSRelationshipDescription: 0x294a60>), name medicine, isOptional 1, isTransient 0, entity Log, renamingIdentifier medicine, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, destination entity Medicine, inverseRelationship logs, minCount 1, maxCount 1, isOrdered 0, deleteRule 1\\\";\\n    note = \\\"(<NSAttributeDescription: 0x2ac810>), name note, isOptional 1, isTransient 0, entity Log, renamingIdentifier note, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\\\";\\n}, subentities {\\n}, userInfo {\\n}, versionHashModifier (null)\";\n    Medicine = \"(<NSEntityDescription: 0x294b10>) name Medicine, managedObjectClassName Medicine, renamingIdentifier Medicine, isAbstract 0, superentity name (null), properties {\\n    active = \\\"(<NSAttributeDescription: 0x2adaa0>), name active, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier active, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 800 , attributeValueClassName NSNumber, defaultValue (null)\\\";\\n    dose = \\\"(<NSAttributeDescription: 0x2adaf0>), name dose, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier amountToTake, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\\\";\\n    hoursBetween = \\\"(<NSAttributeDescription: 0x2adb40>), name hoursBetween, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier hoursBetween, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, attributeType 100 , attributeValueClassName NSNumber, defaultValue 0\\\";\\n    logs = \\\"(<NSRelationshipDescription: 0x2ada40>), name logs, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier logs, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n}, destination entity Log, inverseRelationship medicine, minCount 0, maxCount 0, isOrdered 0, deleteRule 1\\\";\\n    name = \\\"(<NSAttributeDescription: 0x2ad9f0>), name name, isOptional 1, isTransient 0, entity Medicine, renamingIdentifier name, validation predicates (\\\\n), warnings (\\\\n), versionHashModifier (null)\\\\n userInfo {\\\\n    \\\\\\\"com.apple.syncservices.Syncable\\\\\\\" = NO;\\\\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)\\\";\\n}, subentities {\\n}, userInfo {\\n    \\\"com.apple.syncservices.Syncable\\\" = NO;\\n}, versionHashModifier (null)\";\n}, fetch request templates {\n}"; }
like image 334
Ceri Turner Avatar asked Dec 12 '22 00:12

Ceri Turner


2 Answers

You're handing your existing SQL-or-whatever persistent store to Core Data along with the new schema that says that the relevant attribute has a certain name and type. When Core Data then looks at the store it spots that the store isn't in the correct format for the current schema. That causes it to throw the error you're seeing.

If you've yet to release the app then just delete your current storage (delete the app if you're talking iOS) and launch again. Everything should be fine.

If you actually need to perform a migration — e.g. if the old schema has already been deployed — then you obviously need to think about migration.

Based on a skim through, this looks like good information.

You'll end up with both versions of your schema in the project, and have given Core Data enough information to map between them. If you were just talking about a field rename then you could achieve that with just the schemas (check out the 'Renaming ID' field under 'Versioning' in the right hand utilities pane of Xcode when a property is selected and you've clicked to view the data model inspector, the right-most tab) but I'm not sure if that can coerce types. If it can't then you'll additionally end up with a mapping model, another graphical thing that you can edit in Xcode, which definitely can coerce.

like image 116
Tommy Avatar answered May 11 '23 01:05

Tommy


If you're facing such problem, try to run the app in a simulator of another device that you haven't used before and see if it helps you (i.e. iPhone SE instead of iPhone 7). If it does, then removing the corrupted folders should help. Open Terminal and run the following commands:

sudo rm -rf ~/Library/Developer/CoreSimulator/Devices

to remove the simulators' data that might be corrupted,

sudo rm -rf ~/Library/Developer/XCode/DerivedData/

to remove your app's data.

It solved my problem. Hope it helps!

like image 44
Ivan Yurchenko Avatar answered May 10 '23 23:05

Ivan Yurchenko