dev4u
dev4u

Reputation: 2113

core data migration

i am having some issues with Core data migration. i am having 3 versions of my app 1.0, 1.1, 1.2.

for the 1st two versions(1.0 and 1.1), i am having the same data model, but for third version(1.2) i have done some changes in my data model. Now i am getting incompatible issue at version 1.2 of my app(though its a light weight changes).

I am thinking that i have missed the data model version at version 1.1 of my app, as there is no change in the datamodel for 1.0 and 1.1, i havent created another data model version.

Do we need to create a data model version for new app version, even there is no change in the data model between the versions.

sorry if my query is too dum... please suggest..

Upvotes: 1

Views: 778

Answers (2)

dev4u
dev4u

Reputation: 2113

If you want to change the model but also retain the ability to open stores created using a previous version of the model, you must keep the previous version of the model (as a version in a versioned model). Core Data cannot open a store for which it has no compatible model. Thus, if you want to change the model but also retain the ability to open existing stores, you must:

  1. Ensure that you have a versioned model—if you don’t, make the current model into a versioned model.
  2. Before editing the schema , create a new version of the current model.
  3. Edit the new current version of the model, leaving the old version unaltered.

Please refer the link for step by step procedure of versioning

Upvotes: 1

André Morujão
André Morujão

Reputation: 7153

No, you don't need to have a data model version for each app version.

Just to be sure: when you went from 1.1 to 1.2, did you create a new data model version? Or did you simply modify the existing data model? Because for (lightweight) migrations to work, you're supposed to have different versions of the data model; you should NOT just modify the existing model.

Also, you did write the code to perform the automatic lightweight migrations, right?

Upvotes: 1

Related Questions