核心数据存储迁移出现问题
我尝试使用 NSMigrationManager 进行手动迁移来执行核心数据存储的迁移。我已经使用默认向导在 Xcode(版本 4)中创建了一个映射模型,然后在代码中发现它使用
[NSMappingModel mappingModelFromBundles:nil forSourceModel:sourceModel destinationModel:targetModel];
似乎工作正常。唯一的问题是,在我尝试稍微调整映射模型之后(使用描述的方法 此处 将一个实体一分为二),之前的方法不再起作用,它只是返回 nil (这意味着映射模型不再兼容与源模型和目标模型?!)。另外,有趣的是,Xcode 向我显示了映射模型的源模型和目标模型的下拉列表,这些模型没有更改并且设置为正确的模型。
兼容性检查如何工作?映射模型是否确实存在一些更改,导致其与源/目标模型的原始组合不兼容。
更新:从模拟器中卸载应用程序并恢复 sqlite 数据库后,它再次工作,在我看来,好像某些模型没有正确更新..奇怪的是,我现在想知道这是否会在真正的更新或者只是 Xcode/模拟器问题..
I have tried to perform a migration of my Core Data store using the manual migration with the NSMigrationManager. I have created a mapping model in Xcode (version 4) using the default wizard, then in the code found it using
[NSMappingModel mappingModelFromBundles:nil forSourceModel:sourceModel destinationModel:targetModel];
which seemed to work fine. The only problem is that after I tried to tweak the mapping model a little bit (using the method described here to split one entity into two), the previous method doesn't work anymore, it just returns nil (which would mean the mapping model is no longer compatible with the source and destination models ?!). Also, the funny thing is that Xcode shows me dropdowns with both source and destination models for the mapping model which haven't changed and are set to the correct models.
How does the compatibility check work and are there really some changes to the mapping model that can render it incompatible to the original combination of source / destination model.
UPDATE: After uninstalling the app from the simulator and restoring the sqlite database, it works once again, which looks to me as if some of the models wasn't updated correctly.. strange enough, I am now wondering whether this can happen during a real update or it's just an Xcode / Simulator issue..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次使用映射模型进行迁移时,它都会更改持久存储。您必须每次都从相同版本的存储开始,并以完全相同的顺序执行迁移才能获得相同的结果。
我通常建议定期删除并重新创建开发中使用的存储。通常,即使数据集相当大,我也会在每次测试运行开始时这样做。如果您不这样做,那么您将面临因在开发代码中所做的更改而在商店中积累“kruft”的风险。
Every time you use a mapping model to do a migration it alters the persistent store. You have to start with the same version of the store every time and perform the migration in the exact same order to get the same results.
I would generally recommend routinely deleting and recreating stores used in development. Usually I do so at the start of every test run even if the data set is fairly large. If you don't do this, then you run the risk of building up "kruft" in the store by changes you make in the developing code.