Core Data轻量级迁移:无法找到或自动推断迁移的映射模型

发布于 2024-09-29 01:48:05 字数 497 浏览 1 评论 0原文

因此,我创建了数据模型的新版本,并将以前的可选字段设为非可选(为其指定默认值)。根据文档,这应该意味着我的迁移符合轻量级自动迁移的条件。

我还添加了在打开商店时允许执行此操作的选项,同样根据文档:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:

[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,

[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

但是,当我的应用程序启动时,我收到以下错误:

“无法找到或自动推断用于迁移的映射模型”。

有谁知道这里的问题可能是什么?如有任何帮助,我们将不胜感激...谢谢!

So I created a new version of my data model, and made a previously optional field non-optional (giving it a default value). According to the documentation, this should mean my migration is eligible for lightweight, automatic migration.

I also added options that allow this when I open the store, also per the documentation:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:

[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,

[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

When my app is starting, however, I get the following error:

"Can't find or automatically infer mapping model for migration".

Does anyone know what the problem here could be? Any help is appreciated... thanks!

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

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

发布评论

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

评论(1

燕归巢 2024-10-06 01:48:05

您可能已经看过这个,但如果没有... 检测轻量级核心数据迁移

就其他调试代码而言,我发现这很有帮助:

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MyDataStore.sqlite"]];

NSError *error = nil;
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeUrl error:&error];

if (!sourceMetadata)
{
    DLog(@"sourceMetadata is nil");
}
else
{
    DLog(@"sourceMetadata is %@", sourceMetadata);
}

最后,这有点痛苦,但在 Finder 中,您可以为您的应用程序“显示包内容”,然后找到一个名为 .momd 的文件夹并在其中是一个名为“VersionInfo.plist”的文件。这有助于确定您拥有什么以及您想要去哪里。

最后,您可以尝试创建一个映射模型,看看是否有效。我已经与迁移问题搏斗了好几个星期,因此有一长串绝望的调试尝试。

You've probably looked at this, but if not ... Detecting a Lightweight Core Data Migration

In terms of other debugging code, I found this helpful:

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MyDataStore.sqlite"]];

NSError *error = nil;
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeUrl error:&error];

if (!sourceMetadata)
{
    DLog(@"sourceMetadata is nil");
}
else
{
    DLog(@"sourceMetadata is %@", sourceMetadata);
}

And finally, this is kind of a pain but in the Finder you can "Show Package Contents" for your app and then find a folder called .momd and within that is a file called 'VersionInfo.plist'. This has been helpful in identifying what you have and where you're trying to go.

And finally, you could try to create a mapping model and see if that works. I've wrestled with migration issues for weeks, hence the long list of desperate debugging attempts.

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