adriaan
adriaan

Reputation: 1594

Core Data store empty after app update - but data model hasn't changed

I am developing an update for an app that uses Core Data to persist data. I use Magical Record to make dealing with Core Data easier.

This update doesn't involve any changes to the data model.

Yet, when I install the new update on a device, the existing data is deleted, and the app opens with an empty data store. There are no warnings or error message about data migration issues logged. The app also doesn't crash and shouldDeleteStoreOnModelMismatch is set to NO before the Core Data stack is set up ([MagicalRecord setShouldDeleteStoreOnModelMismatch:NO];).

There are no subsequent Core Data issues (new data is persisted fine).

The main changes made to the app in this update are:

In my App Delegate I set up the Core Data stack using:

[MagicalRecord setupAutoMigratingCoreDataStack];

Does anyone have any idea what can be causing this?

Upvotes: 3

Views: 1271

Answers (2)

user1951992
user1951992

Reputation:

After deletion of the store, you need to specify that you want to replace the store with a new one automatically, as so.

[MagicalRecord shouldAutoCreateDefaultPersistentStoreCoordinator]; [MagicalRecord setShouldDeleteStoreOnModelMismatch:YES]; [MagicalRecord setupAutoMigratingCoreDataStack];

Upvotes: 2

casademora
casademora

Reputation: 69687

When you have an empty store, generally it means your migration model isn't step up properly, or your model schema identifiers don't match the version identifiers for the data store.

Make sure you keep both versions of your core data model (before and after). This is how core data matches up the store with your model, and also how to know which version is the newest version.

Upvotes: 2

Related Questions