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

I had the same problem and my solution was to delete the application and install it again because of modifications in database.


You are probably calling persistentStoreCoordinator method from two (or more) different threads. Either directly or indirectly.

As written that method is not thread safe.

It may be you have other methods with the same problem. Typically managedObjectContext exists and is written in a similar way.

There are two ways to solve this problem:

  • use @synchronize to make those methods thread safe
  • move the initialization code out of them and into an init method and modify them to assert/except if the ivar is nil

The second thing that you may also be doing wrong is to modify the context (for example adding new managed objects to it) and then trying to save it, before the store has been initialized.

To solve this make sure you do either one of the following:

  • you do not add any managed object to the context unless you know there is already at least one managed object in it (implying the store is loaded)
  • if you need to add a managed object to the context without checking that there's one already (for example after you initially create the empty store), make sure the store has been initialized already (for example do it when you get the RefetchAllDatabaseData notification and you notice the database is empty).

I solved it by removing the app from simulator and run it again. I guess it happens because the previous version of app does not have core data in it.