1

If I add a new model version and then add an attribute to an entity I get a migration failure. It doesn't matter what the type of the attribute is or whether it is optional or has a default value. If I just add the new model version but don't add the attribute it works OK. I have done this sort of thing lots of times over the past 3 years without problems. Both NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption are set to true. The error I get is shown below.

2018-02-18 12:28:51.771608+0000 Writing Shed[4105:1886727] [error] error: Illegal attempt to save to a file that was never opened. "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation.". Last recorded error = Error Domain=NSCocoaErrorDomain Code=134140 "Persistent store migration failed, missing mapping model."

Does anyone know what might be wrong?

Easiwriter
  • 53
  • 6
  • Even renaming/deleting an attribute is failing! – Easiwriter Feb 18 '18 at 12:46
  • Are you correctly adding the new attribute to the latest version, and including both the previous version(s) and the new one in the project? Xcode’s behaviour isn’t always very intuitive, you need to double-check things when you add a new version. – jcaron Feb 18 '18 at 12:51
  • Thanks. Yes, I have added the attribute correctly (the model has a couple of dozen entities and is on v26). The versions are all in the project file. Like I said, I have done this loads of times and know the pitfalls. – Easiwriter Feb 18 '18 at 12:54
  • Obviously you’ve done something wrong at some point, there shouldn’t be a problem with such a simple migration, but sadly Xcode makes it easy to fall into quite a few traps. You may want to check out https://stackoverflow.com/questions/20983542/missing-mapping-model-after-editing-the-model and https://stackoverflow.com/questions/2492103/core-data-migration-problem-persistent-store-migration-failed-missing-source for things to try. – jcaron Feb 18 '18 at 13:01

1 Answers1

2

I've found the problem. I'm developing an app on Mac OS that is already available on IOS. They sync CoreData via iCloud. At some point while working on the Mac I added some attributes to the model that weren't optional or defaulted. To cut a long story short this caused problems with an IOS store that predated the changes, so that's when the migration failed (can't migrate to non-optional/non-defaulted attributes). I'm still not sure how I got into this situation because I'm usually very careful with CoreData, but hey stuff happens. Thanks for the comments which made me look deeper.

Easiwriter
  • 53
  • 6