在非连续版本之间迁移时,Core Data Migration错误 [英] Core Data Migration error when migrating between non-consecutive versions

查看:141
本文介绍了在非连续版本之间迁移时,Core Data Migration错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题




  • 我有13个版本的核心数据模型。

  • 我已经制作了13个映射模型(V1-V2,V2-V3等)。

  • 我已启用自动迁移。

  • 在两个不连续版本(例如V11-V13)之间迁移时,迁移失败,错误为:



  • 找不到迁移的映射模型




我尝试了



为每个可能的版本组合创建一个映射模型。



对于版本14,我需要创建14个不同的映射模型。手动。 ug。



代码



以下是迁移时传递的选项:

  [persistentStoreCoordinator addPersistentStoreWithType:[self storeType] 
configuration:nil
URL:url
options:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:NO],NSReadOnlyPersistentStoreOption,
nil]
error:& error]){



数据模型



我的数据模型非常复杂, http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip



我现在没有在我的数据模型中使用任何版本哈希修饰符或重命名标识符。

解决方案

请参阅这个Stack Overflow问题:跨越核心数据迁移多个版本升级



基本上,您不需要创建完整的映射模型集。您只需要在每对连续模型之间映射模型,然后可以逐步将任何旧模型通过中间模型迁移到最新模型。



性能可能不是好的,取决于你的商店,因为你不是在一个单一的步骤进行迁移。它可能是足够好,虽然,可能值得它不必创建一套完整的映射模型。您还可以测试此方法的效果,以确定是否需要在模型的不连续版本之间创建地图。



Marcus Zarra(Core Data aficionado extraordinaire)具有以下代码: http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration /AppDelegate.m



(我只是想问这个问题,但感谢LazyTwitter我被Aaron Tuller指向这个答案: https://twitter.com/tullera/status/57708304683642880


The Problem

  • I've got 13 versions of my core data model.
  • I've made 13 mapping models (V1-V2, V2-V3 etc)
  • I've got automatic migration switched on.
  • On migration between two consecutive versions (e.g. V12-V13) the migration works perfectly
  • On migration between two non-consecutive versions (e.g. V11-V13) the migration fails with the error:

    Can't find mapping model for migration

What I've tried

Creating a mapping model for every possible combination of versions. This works, but it's a real hassle.

For version 14 I'll need to make 14 different mapping models. Manually. Ugh.

Code

Here's the options I pass in for migration:

[persistentStoreCoordinator addPersistentStoreWithType:[self storeType]
                                          configuration:nil 
                                                    URL:url 
                                                options:[NSDictionary dictionaryWithObjectsAndKeys:
                                                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                                         [NSNumber numberWithBool:NO], NSReadOnlyPersistentStoreOption,
                                                         nil]
                                                  error:&error]){

Data Model

My data model is pretty complex, but here it is: http://dl.dropbox.com/u/136780/Engine_V2_DataModel.xcdatamodeld.zip

I'm not using any version hash modifiers or renaming identifiers in my data model right now.

解决方案

See this Stack Overflow question: Core Data Migration Across Multiple Version Upgrades

Basically, the gist is that you don't need to create the complete set of mapping models. You just need mapping models between each pair of successive models, and then you can progressively migrate any old model through the intermediate models to the newest model.

The performance may not be good depending on your store, because you're not doing the migration in one single step. It may be good enough, though, and may be worth it to not have to create the complete set of mapping models. You can also test out the performance of this method to determine whether you need to create maps between non-successive versions of your model.

Marcus Zarra (Core Data aficionado extraordinaire) has the code here: http://media.pragprog.com/titles/mzcd/code/ProgressiveMigration/AppDelegate.m

(I was just about to ask this question, but thanks to LazyTwitter I was pointed to this answer by Aaron Tuller: https://twitter.com/tullera/status/57708304683642880 )

这篇关于在非连续版本之间迁移时,Core Data Migration错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆