Core Data migration problem: “Persistent store migration failed, missing source managed object model.”

后端 未结 5 1232
耶瑟儿~
耶瑟儿~ 2020-12-16 19:36

The Background

  • A Cocoa Non Document Core Data project with two Managed Object Models.
  • Model 1 stays the same. Model 2 has changed, s
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 20:19

    I had a similar problem. I have used +modelByMergeingModels:, but I did not use Mapping Model. However 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.

提交回复
热议问题