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

John Gallagher picture John Gallagher · Mar 22, 2010 · Viewed 16.2k times · Source

The Background

  • A Cocoa Non Document Core Data project with two Managed Object Models.
  • Model 1 stays the same. Model 2 has changed, so I want to migrate the store.
  • I've created a new version by Design > Data Model > Add Model Version in Xcode.
  • The difference between versions is a single relationship that's been changed from to a one to many.
  • I've made my changes to the model, then saved.
  • I've made a new Mapping Model that has the old model as a source and new model as a destination.
  • I've ensured all Mapping Models and Data Models and are being compiled and all are copied to the Resource folder of my app bundle.
  • I've switched on migrations by passing in a dictionary with the NSMigratePersistentStoresAutomaticallyOption key as [NSNumber numberWithBool:YES] when adding the Persistent Store.
  • Rather than merging all models in the bundle, I've specified the two models I want to use (model 1 and the new version of model 2) and merged them using modelByMergingModels:

The Problem

No matter what I do to migrate, I get the error message:

"Persistent store migration failed, missing source managed object model."

What I've Tried

  • I clean after every single build.
  • I've tried various combinations of having only the model I'm migrating to in Resources, being compiled, or both.
  • Since the error message implies it can't find the source model for my migration, I've tried having every version of the model in both the Resources folder and being compiled.
  • I've made sure I'm not making a really basic error by switching back to the original version of my data model. The app runs fine.
  • I've deleted the Mapping Model and the new version of the model, cleaned, then recreated both.
  • I've tried making a different change in the new model - deleting an entity instead.

I'm at my wits end.

I can't help but think I've made a huge mistake somewhere that I'm not seeing. Any ideas?

Answer

Marcus S. Zarra picture Marcus S. Zarra · Mar 22, 2010

Two possibilities:

  1. Your source model in your app does not match the actual store on disk.
  2. Your mapping model does not match your source model.

Turn on Core Data debugging and you should be able to see the hashes that Core Data is looking for when it is doing the migration. Compare these hashes to what is in your store on disk and see if they match up. Likewise the debugging should let you see the hashes in the mapping model to help you match everything up.

If it is just your mapping model that is misaligned, you can tell it to update from source from the design menu in Xcode. If you are missing the actual source model for your store file on disk then you can look in your version control system or try using an automatic migration to get that file to migrate to the model that you believe is the source.

Update 1

The location for changing the source and destination models has moved to the bottom of the editor window: