我对Core Data相当新,并且只将我的应用程序版本1.0和1.1.1发布到App Store。
在开始开发1.2.0时,我成功完成了Core Data轻量级迁移,以创建新模型。一切都在运作。我最近发现了一个与我的某个实体有关的问题,因此我必须将属性从NSDate
更改为NSString
。考虑到这一点,我再次进行了迁移并将其命名为1.2.x.这被选为当前版本,但是当我运行我的应用程序时,我得到:
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)";
应用程序无法运行此错误。我已经完成并将所有NSDate
更改为NSString
但我觉得这个错误正在发生,因为它仍然无效。
我显然不能让我的用户卸载并重新安装应用程序(适用于Xcode);在没有用户重新安装的情况下,我能做些什么来实现这个目标吗?为什么Core Data轻量级迁移不起作用?
更新 我有两个问题:
1)因为我只是更改了属性的数据类型,我是否需要对另一个版本进行轻量级迁移,还是只需更改以前创建的新版本模型的属性数据类型? / p>
2)我在我的应用程序中有以下代码,并且在中止代码中使用上面的错误调用断点异常:
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
//abort();
如果我对此进行评论,就像我上面所说的那样,该应用程序可以运行,但此问题顶部的错误输出仍然存在。此外,更重要的是,数据不会迁移。这有多安全?这使我对使用这些问题运送我的应用程序感到紧张。
答案 0 :(得分:1)
您必须将 NSDate值转换为NSString。仅改变类型是不够的。如果你已经这样做了,你的问题就不清楚了。您获得的具体错误是NSMigrationMissingMappingModelError
,在CoreDataErrors.h
中定义。 Core Data不知道如何从NSDate转到NSString。您必须提供从一个映射到另一个的方法。