将Core Data属性从Integer 16更改为String时,为什么会出现此错误?

时间:2012-07-10 18:35:11

标签: ios core-data

我有一个Core Data模型,其中一个属性当前设置为Integer 16.我现在想要更改属性名称并更改其类型,但保留当前数据。我已将名称更改排序,并且它正在运行而没有问题。

在尝试更改数据类型时,我得到以下非常长的错误,我该怎么做才能解决它?

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}"; }

3 个答案:

答案 0 :(得分:9)

您将现有的SQL或任何持久性存储交给Core Data以及表示相关属性具有特定名称和类型的新架构。然后,当Core Data查看商店时,它会发现商店的格式与当前架构的格式不同。这导致它抛出你所看到的错误。

如果您尚未发布该应用,则只需删除当前存储空间(如果您正在使用iOS,则删除该应用)并重新启动。一切都应该没问题。

如果您确实需要执行迁移 - 例如如果已经部署了旧模式 - 那么你显然需要考虑迁移。

根据浏览情况,this看起来很不错。

您最终会在项目中使用两个版本的模式,并为Core Data提供足够的信息以在它们之间进行映射。如果您只是在谈论字段重命名,那么您只需使用模式即可实现(在选择属性并且您单击时,在Xcode的右侧实用程序窗格中查看“版本控制”下的“重命名ID”字段)查看数据模型检查器,最右边的选项卡)但我不确定是否可以强制类型。如果它不能,那么你还会得到一个映射模型,你可以在Xcode中编辑的另一个图形化的东西,绝对可以强制。

答案 1 :(得分:1)

如果您遇到此类问题,请尝试在之前未使用的其他设备的模拟器中运行该应用,看看它是否对您有所帮助(即 iPhone SE 而不是iPhone 7)。如果是这样,那么删除损坏的文件夹应该会有所帮助。 打开终端并运行以下命令:

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

删除模拟器&#39;可能已损坏的数据,

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

删除您应用的数据。

它解决了我的问题。希望它有所帮助!

答案 2 :(得分:0)

我在Xcode 10和Swift 4.2中也遇到了同样的问题。

当我更改CoreData的实体String to Int16时,我从设备上卸载了该应用程序并重新安装。

对我有用。