Question

I've got an app that has had many many core data migrations, with several developers working on the project, at one point it appears there was a failure to properly migrate the core data model. The end result is that people who upgraded from a particular version of the app to the current version of the app are unable to save their context to the store (this save occurs when the application enters background).

The error logged is as follows :

This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.

Fortunately, the users are unlikely to notice too much from this crash and error, as it occurs during the app's exit and the app is designed to simply retrieve any data from the web that is missing locally so a failed save isn't as critical as it would be if any user created data was being lost. Of course, this is less than ideal, to have to redownload data that is just not being saved to the store on app exit.

My question ultimately is how do I go about fixing this issue going forward?

My idea is to release a minor update that completely resets the core data persistent model. Wipe out any old data stores, and start fresh (remember the data all comes from the server). There will be no data loss to the user, and this would solve things going forward. Is there a better idea?

Also, if that were how I decided to do things, how exactly would I go about doing this properly? Would I just look in my bundle and delete any .momd files and then recreate a new one with a different name? Or is deleting unnecessary and just giving new names would give the desired reusults?

Was it helpful?

Solution

To fully reset you can add a check in your applicationDidFinishLaunching which:

  1. Check for a flag in the user defaults that indicates you already migrated
  2. If not migrated, delete the current store file
  3. Set the flag in user defaults so you don't 'upgrade' again in future
  4. That's it, open the store and download the required data

To fix:

  1. Start at your first version and progressively checkout each version and run it till you find the problem
  2. Once you found the problem, work out which migration is bad - what causes the crash
  3. Fix the migration (depends very much what the migration is, ask a new question...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top