核心数据:存储无法保存实体实例(Cocoa 错误:134020)
这是最奇怪的错误。 互联网表明这是针对 Tiger 的问题;除了我实际上针对的是 iOS 3 和 4。
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)}
在出现此错误之前,我向 Core Data 添加了大量数据,但我保存了两次(中间一次,最后一次)。第一次保存后一切都很好,第二次保存导致了问题,所以我将发布我在第一次保存之后但第二次保存之前使用的代码。
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 子类上调用的便捷方法可以找到 在这里。
我在应用程序的其他地方(运行后很长时间)有可以添加/编辑/删除上面引用的所有实体的方法。该错误不会每次都发生在同一实体上。
任何帮助将不胜感激!这是一个棘手的问题。
This is the strangest error. The internet suggests that this is an issue with targeting Tiger; except that I'm actually targeting iOS 3 and 4.
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)}
I'm adding a lot of data to Core Data before I get this error, but I'm saving twice (once in the middle, then again at the end). Everything is fine after the first save, it's the second save that is causing the problem, so I'll post the code that I'm using after the first but before the second.
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;
}
}
The convenience methods I'm calling on NSManagedObject subclasses can be found here.
I have methods elsewhere in the app (long after this runs) that can add/edit/delete all of the entities referenced above. The error doesn't occur on the same entity every time.
Any help would be greatly appreciated! This is a tricky one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在以下情况下遇到此错误:
一定的配置。
到其中一项配置。
将新实体添加到配置后,一切正常
I had this error in the following situation:
a certain configuration.
to one of the configurations.
After adding the new entity to a configuration, everything works fine
对于通过 Google 找到此页面的其他人:我遇到了类似的问题,其原因与上述解决方案无关。
触发错误的代码正在为一个商店播种,该商店使用与现有商店相同的托管对象模型。
错误的代码是
相反
,这可能看起来多余,但对我来说消除了错误。
For other people that find this page via Google:I had a similar problem with a cause unrelated to the solution above.
The code that triggered the error was seeding a store that used the same managed object model from an existing store.
The wrong code was
Instead do
which may seem redundant, but got rid of the error for me.
好吧,我发现了问题所在。
在我发布之前的代码中,我使用 RestKit 的 Seeder 对象从本地 json 文件为我的数据库播种,然后在运行后继续添加对象。但在您调用
finalizeSeedingAndExit
之前,它实际上不会将对象提交到对象存储中。调用该函数来播种数据的第一部分,然后注释掉播种器并再次运行,修复了这个奇怪的错误。
Okay, I discovered what the problem was.
In the code before what I posted, I used RestKit's seeder object to seed my database from a local json file, and then I continued to add objects after it ran. But it doesn't actually commit the objects to the object store until you call
finalizeSeedingAndExit
.Calling that function to seed the first part of my data, then commenting out the seeder and running again, fixed this strange, strange, error.