核心数据迁移的验证错误

发布于 2024-08-07 03:26:01 字数 3088 浏览 1 评论 0原文

我在 Mac OS X 10.5 上使用 Core Data 时遇到一个非常烦人的错误。

我的应用程序中的所有实体都有共享相同名称的类。

到目前为止,我已经完成了 5 次迁移,没有出现任何问题。

我正在使用 XML 数据存储。 我的数据模型 V5 包含 13 个实体,其中 4 个是抽象的。它看起来像这样: 替代文本 http://synapticmishap.co.uk/ObjectModel.jpg

我的内容执行

  1. 创建我的数据的新版本 模型 - 这是 V6。

  2. 添加一个新实体(JGToolbarWindow) 并将父级设置为 JGWindowBase。

  3. 添加了一个映射模型,来自 V5至V6。已保存。

  4. 设置当前版本为V6。

  5. 构建和调试。

我已在持久存储协调器选项字典中打开自动迁移。

问题

  1. 收到错误 - “多重验证 发生错误。”

  2. 我设置了一个断点并检查了 验证错误。有一个很长的 验证错误列表 - 那里 似乎每个数据输入都是一个。

  3. 似乎它正在剥离所有 的关系,因为我的一位 属性-应用程序-设置为 是必需的,这算作 验证错误。

  4. 看来问题出在 迁移无法迁移 关系...尽管 显然到目前为止一切都没有改变 随着关系的发展。

  5. 当我查看 ~/Library/Application 时 支持/我的应用程序名称/我看到一个 XML 具有相同名称的数据存储 附加 .xml.new 查看时 这个文件在文本编辑器中,所有的 关系确实已经 时

我尝试过的

  1. 创建一个新的 XML 数据存储并 将一些物品放入其中, 然后再试一次。我也得到同样的结果 每个项目的错误。

  2. 清理和重建。

  3. 确保旧的 .xml.new 来自 先前的验证已 已删除。

  4. 删除新模型版本并 重复我的行动以确保我 没有搞砸什么。

  5. 为每个添加映射条目 抽象类,它们是 默认忽略。添加了全部 属性和关系。仍然 完全相同的错误。

  6. 尝试添加一个新实体 没有类,只是基于 NSManagedObject 其中有 JGWindowBase 作为父级。再次, 失败。

我认为唯一发生变化的是模型底层类中的一些内部逻辑。但这些都是微小的变化,我无法理解它是如何顺利迁移的,而现在似乎没有任何变化。

我尝试从重命名的最新数据存储进行全新迁移,但遇到了完全相同的问题。这意味着我必须解决这个问题才能使任何数据迁移工作正常进行。

错误

当我在下面的 presentError 行放置一个断点

if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                                  configuration:nil 
                                                            URL:url 
                                                        options:options 
                                                          error:&error]){
          [[NSApplication sharedApplication] presentError:error];
}

并检查错误 userInfo 时,我收到很多这样的错误:

Error Domain=NSCocoaErrorDomain Code=1570 UserInfo=0x67ebfd0 "item is a required value."

po (NSArray *)0x67ebfd0

给出:

NSLocalizedDescription = "item is a required value.";
NSValidationErrorKey = item;
NSValidationErrorObject = <NSManagedObject: 0x45d5830> (entity: JGLogEntry; id: 0x4baccb0 <x-coredata://B597E13E-BE74-402E-BF00-5E1D57898406/JGLogEntry/p13942> ; data: {
duration = nil;
item = nil;                   // <<< Here's the problem.
processBundleID = nil;
processID = nil;
processName = nil;
startTime = 2009-10-09 16:41:44 +0100;
stopTime = 2009-10-09 16:42:17 +0100;
windowDocumentPathOrURL = nil;
windowID = nil;
windowTitle = nil;

这一切确实告诉我的是它删除了连接到项目的关系,这是一个必需的属性,这就是为什么它告诉我存在验证错误。应用程序也有一个完整的负载,这是另一个必需的属性。

在我看来,问题不在于验证错误本身,而在于它似乎根本没有迁移任何关系

我正在为此抓狂。我真的非常感谢一些帮助。最后引用一句星球大战的名言:

“帮助我,Stack Overflow。你是我的 只有希望。”

I'm encountering a very annoying error using Core Data on Mac OS X 10.5.

All entities have classes in my application which share the same names.

Up to this point, I've done 5 migrations without problems.

I'm using the XML data store.
I've got V5 of my data model with 13 entities, 4 of which are abstract. It looks like this:
alt text http://synapticmishap.co.uk/ObjectModel.jpg

What I do

  1. Create a new version of my data
    model - this is V6.

  2. Add a new entity (JGToolbarWindow)
    and set the parent to JGWindowBase.

  3. Added a mapping model that goes from
    V5 to V6. Saved it.

  4. Set the current version to be V6.

  5. Build and Debug.

I've got automatic migration switched on in the Persistent Store Coordinator options dictionary.

The Problem

  1. Get an error - "Multiple validation
    errors occurred."

  2. I've set a breakpoint and examined
    the validation errors. There's a long
    list of validation errors - there
    seems to be one for every data entry.

  3. It seems that it's stripping out ALL
    the relationships and since one of my
    properties - application - is set to
    be required, this counts as a
    validation error.

  4. So it seems the problem lies with the
    migration not being able to migrate
    the relationships... even though
    apparently nothing has changed as far
    as relationships go.

  5. When I look in ~/Library/Application
    Support/Name of my app/ I see an XML
    Data Store that's got the same name
    appended by .xml.new When looking at
    this file in a text editor, all the
    relationships have indeed been
    stripped out.

What I've tried

  1. Creating a new XML data store and
    putting a handful of items in it,
    then trying again. I get the same
    errors for each item.

  2. Cleaning and rebuilding.

  3. Making sure the old .xml.new from
    previous validation has been
    deleted.

  4. Deleting the new model version and
    repeating my actions to make sure I
    didn't screw something up.

  5. Adding mapping entries for each of
    the abstract classes, which are
    ignored by default. Added all
    attributes and relationships. Still
    exactly the same error.

  6. Tried adding a new entity that
    doesn't have a class, just based on
    NSManagedObject which has
    JGWindowBase as a parent. Again,
    failed.

The only thing I can think that has changed is some of my internal logic in the classes underlying the model. But these are minor changes and I can't understand how it was migrating fine, and now it's not when nothing appears to have changed.

I've tried a brand new migration from a renamed latest data store and have exactly the same problems. Which means I've got to solve this problem for any data migration to work.

Errors

When I put a breakpoint at the presentError line below

if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                                  configuration:nil 
                                                            URL:url 
                                                        options:options 
                                                          error:&error]){
          [[NSApplication sharedApplication] presentError:error];
}

and examine the error userInfo, I get lots of errors like this:

Error Domain=NSCocoaErrorDomain Code=1570 UserInfo=0x67ebfd0 "item is a required value."

po (NSArray *)0x67ebfd0

gives:

NSLocalizedDescription = "item is a required value.";
NSValidationErrorKey = item;
NSValidationErrorObject = <NSManagedObject: 0x45d5830> (entity: JGLogEntry; id: 0x4baccb0 <x-coredata://B597E13E-BE74-402E-BF00-5E1D57898406/JGLogEntry/p13942> ; data: {
duration = nil;
item = nil;                   // <<< Here's the problem.
processBundleID = nil;
processID = nil;
processName = nil;
startTime = 2009-10-09 16:41:44 +0100;
stopTime = 2009-10-09 16:42:17 +0100;
windowDocumentPathOrURL = nil;
windowID = nil;
windowTitle = nil;

All this really tells me is that it's removed the relationship connected to item, which is a required property which is why it's telling me there are validation errors. There are a whole load for application too, which is the other required property.

As I see it, the problem isn't with the validation errors as such, it's that it seems to be not migrating any relationships at all.

I'm pulling my hair out with this. I'd really, really appreciate some help. And finally, a Star Wars quote:

"Help me, Stack Overflow. You're my
only hope."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦晓ヶ微光ヅ倾城 2024-08-14 03:26:01

升级到 Snow Leopard

Snow Leopard 似乎解决了这个问题 - 自升级以来我在迁移数据方面没有遇到任何问题。

或者,我认为它可能会消失,因为我切换到 SQLite 数据存储,尽管我认为抽象对象的迁移更有可能在 Leopard 上有点损坏。

Upgrade To Snow Leopard

Snow Leopard seems to address this issue - I've not had any problems with migrating data since the upgrade.

Alternatively, I suppose it may gone away because I switched to the SQLite data store, although I think it's more likely that migrations with abstract objects are a bit broken on Leopard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文