开发者

Does merge model can work with light data migration?

This problem bothers me a lot and try to get some help.I knew this is a old one but I still don't find the solution.

In my application, I try to use modelByMergingModels to gather all my data models into one, then pass to the persistentStoreCoordinator. Everything is fine until I need to implement the data migration just in case the data model will be changed in the future.

Here are the steps I did. 1. Design-Add modal version to create a new data 2. Add a new attribute,SAVE 3. Add the lig开发者_开发百科ht data migration options dictionary to addPersistentStoreWithType method 4. Run the programs and get the error. "Can't find model for source store";

However, if I change my managedObjectModel accessor to init only one data model and get rid of the modelByMergeingModels or mergedModelFromBundles. It just works.

So my question is, does data migration works when I use merge models or mergedModelFromBundles?

What's the best way if I have multiple data models and try to implement the data migration.

Hope the question make sense. Many thanks


This is currently a bug in Core Data. Please open a radar at http://bugreport.apple.com so that Apple will know more people are having this problem.

As for a workaround, I am not aware of one, however you may try migrating the models individually.


Merging models does not work with lightweight data migration.

From the Apple Docs:

To perform automatic lightweight migration, Core Data needs to be able to find the source and destination managed object models itself at runtime.

If you use +modelByMergeingModels: than that is used for the destination model. However Core Data will not be able to find source model. Source model has been created using +modelByMergeingModels: in older version of the application and Core Data does try to merge models to find out the source model.

What I ended up doing is that I have (manually) created a new merged .xcdatamodeld by editing the XML files of the models, added it into the project, removed the separate .xcdatamodelds from Compile Sources and instead of using +modelByMergeingModels: use NSManagedObjectModel's -initWithContentsOfURL: with the URL of the new merged model. I'll probably create a script that will automatically merge the models in the future.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜