2011-08-04 41 views
5

這是最奇怪的錯誤。 The internet表明這是針對Tiger的問題;所不同的是,我居然中定位iOS 3和4核心數據:商店無法保存實體實例(可可錯誤:134020)

Error Domain=NSCocoaErrorDomain Code=134020 "The operation couldn\u2019t be completed. (Cocoa error 134020.)" UserInfo=0xc502350 {NSAffectedObjectsErrorKey=<PartRecommendation: 0x6a113e0> (entity: PartRecommendation; id: 0x6a0d0e0 <x-coredata:///PartRecommendation/tAE2B5BA2-44FD-4B62-95D7-5B86EBD6830014> ; data: { 
    "_rkManagedObjectSyncStatus" = 0; 
    name = "Thin canopy cover"; 
    part = nil; 
    partRecommendationId = 6; 
    partType = "0x6a07f40 <x-coredata:///PartType/tAE2B5BA2-44FD-4B62-95D7-5B86EBD683003>"; 
}), NSUnderlyingException=Store <NSSQLCore: 0x5f3b4c0> cannot hold instances of entity (<NSEntityDescription: 0x6d2e5d0>) name PartRecommendation, managedObjectClassName PartRecommendation, renamingIdentifier PartRecommendation, isAbstract 0, superentity name PartOption, properties { 
    "_rkManagedObjectSyncStatus" = "(<NSAttributeDescription: 0x6d37550>), name _rkManagedObjectSyncStatus, isOptional 0, isTransient 0, entity PartRecommendation, renamingIdentifier _rkManagedObjectSyncStatus, validation predicates (\n), warnings (\n), versionHashModifier (null), attributeType 100 , attributeValueClassName NSNumber, defaultValue 0"; 
    name = "(<NSAttributeDescription: 0x6d37c10>), name name, isOptional 1, isTransient 0, entity PartRecommendation, renamingIdentifier name, validation predicates (\n), warnings (\n), versionHashModifier (null), attributeType 700 , attributeValueClassName NSString, defaultValue (null)"; 
    part = "(<NSRelationshipDescription: 0x6d2e660>), name part, isOptional 1, isTransient 0, entity PartRecommendation, renamingIdentifier part, validation predicates (\n), warnings (\n), versionHashModifier (null), destination entity Part, inverseRelationship recommendation, minCount 1, maxCount 1"; 
    partRecommendationId = "(<NSAttributeDescription: 0x6d2e6d0>), name partRecommendationId, isOptional 1, isTransient 0, entity PartRecommendation, renamingIdentifier partRecommendationId, validation predicates (\n), warnings (\n), versionHashModifier (null), attributeType 100 , attributeValueClassName NSNumber, defaultValue 0"; 
    partType = "(<NSRelationshipDescription: 0x6d2e720>), name partType, isOptional 1, isTransient 0, entity PartRecommendation, renamingIdentifier partType, validation predicates (\n), warnings (\n), versionHashModifier (null), destination entity PartType, inverseRelationship partRecommendations, minCount 1, maxCount 1"; 
}, subentities { 
}, userInfo { 
}, versionHashModifier (null)} 

我加入了大量的數據,以核心數據之前,我得到這個錯誤,但我又節省了兩次(一次在中間,然後最後)。第一次保存後一切正常,這是導致問題的第二次保存,因此我將在第一次之後但在第二次之前發佈我正在使用的代碼。

Landscape *landscape = [Landscape object]; 

Type *type = [Type object]; 
type.name = @"tree"; 

MeasurementType *caliperType = [MeasurementType object]; 
MeasurementType *heightType = [MeasurementType object]; 

InventoryTree *inventoryTree = [InventoryTree object]; 
inventoryTree.landscape = landscape; 
inventoryTree.type = type; 

Assessment *assessmentTree = [Assessment object]; 
assessmentTree.inventoryItem = inventoryTree; 
assessmentTree.type = type; 
[[inventoryTree mutableSetValueForKeyPath:@"assessments"] addObject:assessmentTree]; 

Measurement *caliper = [Measurement object]; 
Measurement *height = [Measurement object]; 
caliper.type = caliperType; 
height.type = heightType; 
[[assessmentTree mutableSetValueForKey:@"measurements"] addObjectsFromArray:[NSArray arrayWithObjects:caliper, height, nil]]; 

for (PartType *pType in [PartType allObjects]) { 
    pType.type = type; 
     Part *treePart = [Part object]; 
     treePart.partType = pType; 
     [[assessmentTree mutableSetValueForKey:@"parts"] addObject:treePart]; 
     for (PartCondition *cond in pType.partConditions) { 
      cond.partType = pType; 
     } 
     for (PartRecommendation *rec in pType.partRecommendations) { 
      rec.partType = pType; 
     } 
} 

我在調用NSManagedObject子類的便利方法可以找到here

我有應用程序中的其他地方(運行很久),可以添加/編輯/刪除上面引用的所有實體。這個錯誤每次都不會在同一個實體上發生。

任何幫助將不勝感激!這是一個棘手的問題。

回答

1

好的,我發現了問題所在。

在我發佈之前的代碼中,我使用了RestKit的播種器對象來從本地json文件播種我的數據庫,然後在運行後繼續添加對象。但是,除非您致電finalizeSeedingAndExit,否則它實際上不會將對象提交到對象存儲庫。

調用該函數播種我的數據的第一部分,然後註釋播種機並再次運行,修復了這個奇怪的,奇怪的錯誤。

9

我有這個錯誤在以下情況:

  • 我用我的CoreData機型配置。每個實體都被分配到 的某種配置。
  • 我添加了一個新的實體,並忘記將它分配給其中一個配置 。
  • 這似乎導致可可錯誤:134020.

添加新實體的配置之後,一切工作正常

12

對於通過谷歌找到這個網頁其他人:我有一個類似的問題原因與上述解決方案無關。

觸發錯誤的代碼是爲使用現有商店中相同管理對象模型的商店進行種子播種。

的錯誤代碼是

NSManagedObject *newObj = [[NSManagedObject alloc] initWithEntity:[obj entity] insertIntoManagedObjectContext:moc] 

而是做

NSManagedObject *newObj = [[NSManagedObject alloc] initWithEntity:[NSEntityDescription entityForName:obj.entity.name inManagedObjectContext:moc] insertIntoManagedObjectContext:moc] 

這看起來是多餘的,但擺脫了錯誤的我。

+0

感謝這幫了我。它似乎不會修復它,但它確實。我唯一的猜測是核心數據在這方面存在一個缺陷。 – Andrew

+0

這個男人節省了我很多時間,完美的工作! – Shizam

+0

感謝您的提示! –