gpt4 book ai didi

core-data - 核心数据关系导致删除后保存错误

转载 作者:行者123 更新时间:2023-12-02 21:46:47 25 4
gpt4 key购买 nike

这个问题可能是一个不太可能的问题。当我删除实体后保存时,我无法找出核心数据项目中出现的错误。

我有两个主要的工作实体:一套服装和一篇文章。我可以毫无问题地创建它们,但是当我删除它们时,我收到以下错误日志:

对于服装:

2009-09-22 20:17:37.771 itryiton[29027:20b] Operation could not be completed. (Cocoa error 1600.)
2009-09-22 20:17:37.773 itryiton[29027:20b] {
NSLocalizedDescription = "Operation could not be completed. (Cocoa error 1600.)";
NSValidationErrorKey = outfitArticleViewProperties;
NSValidationErrorObject = <Article: 0x12aa3c0> (entity: Article; id: 0x12b49a0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/Article/p1> ; data: {
articleID = 2009-09-22 19:05:19 -0400;
articleImage = 0x12b4de0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/ArticleImage/p1>;
articleType = nil;
attributeTitles = "(...not nil..)";
color = nil;
comment = nil;
dateCreated = 2009-09-22 19:05:19 -0400;
designer = nil;
imageView = "(...not nil..)";
location = "(...not nil..)";
outfitArticleViewProperties = (
0x12b50f0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/OutfitArticleViewProperties/p1>
);
ownesOrWants = 0;
pattern = nil;
price = nil;
retailer = nil;
thumbnail = "(...not nil..)";
washRequirements = nil;
wearableSeasons = nil;
});
NSValidationErrorValue = {(
<OutfitArticleViewProperties: 0x1215340> (entity: OutfitArticleViewProperties; id: 0x12b50f0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/OutfitArticleViewProperties/p1> ; data: {
article = 0x12b49a0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/Article/p1>;
articleViewPropertiesID = nil;
outfit = nil;
touch = nil;
view = "(...not nil..)";
})
)};
}

如果我删除一篇文章,我会得到:

2009-09-22 18:58:38.591 itryiton[28655:20b] Operation could not be completed. (Cocoa error 1560.)
2009-09-22 18:58:38.593 itryiton[28655:20b] DetailedError: {
NSLocalizedDescription = "Operation could not be completed. (Cocoa error 1600.)";
NSValidationErrorKey = articleImage;
NSValidationErrorObject = <Article: 0x12aa340> (entity: Article; id: 0x12b3f10 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/Article/p1> ; data: {
articleID = 2009-09-22 18:58:26 -0400;
articleImage = 0x12b4d00 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/ArticleImage/p1>;
articleType = nil;
attributeTitles = "(...not nil..)";
color = nil;
comment = nil;
dateCreated = 2009-09-22 18:58:26 -0400;
designer = nil;
imageView = "(...not nil..)";
location = "(...not nil..)";
outfitArticleViewProperties = (
0x12b5010 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/OutfitArticleViewProperties/p1>
);
ownesOrWants = 0;
pattern = nil;
price = nil;
retailer = nil;
thumbnail = "(...not nil..)";
washRequirements = nil;
wearableSeasons = nil;
});
NSValidationErrorValue = <ArticleImage: 0x12ad600> (entity: ArticleImage; id: 0x12b4d00 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/ArticleImage/p1> ; data: {
article = 0x12b3f10 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/Article/p1>;
image = "(...not nil..)";
});
}

1600 错误是:

NSValidationRelationshipDeniedDeleteError
Error code to denote some relationship
with delete rule NSDeleteRuleDeny is
non-empty.

Available in Mac OS X v10.4 and later.

Declared in CoreDataErrors.h.

但我一生都看不出哪种关系会阻止删除。如果某个核心数据向导能够看到我的方法的错误,我会感到谦卑。

我无法将此标记为已解决,因为我没有真正解决它,但我确实有一个可行的解决方法。在每个 managedObjects.m 中,我添加了一个如下所示的方法:

-(void) deleteFromManangedObjectContext{ 
self.outfit = nil;
self.article = nil;
[[self managedObjectContext] deleteObject:self];
}

所以你可以看到,首先我手动清除关系,然后让对象删除自身。在其他对象中,我的删除方法不是nil-ing,而是在某些对象关系上调用,以获得级联。

最佳答案

我刚刚遇到删除失败的问题,并想到了这个问题。我已经弄清楚了我的问题,并认为我也会分享这个问题,也许有人也会遇到同样的问题。

我犯的错误是,我尝试删除的对象 (A) 与另一个对象 (B) 有关系,删除规则为 NULL。但是,对象 B 也与 A 存在关系,并且该关系是非可选的。因此,当我删除A时,B与A的关系变为空,这是不允许的。当我将删除规则更改为级联时,它起作用了。

关于core-data - 核心数据关系导致删除后保存错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1463382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com