I have a version 1.0 , currently distributed in app store. The version uses a model of version 1.0. Some of the entities in the store of the model are populated with predefined data so the app is packaged with a store already contained this data, the app doesn't let the users change these entities (only read). The store is of type SQLite.
I have found out that in version 1.0 ,there's a property in an entity (one of those predefined entities) that contains wrong value (for all instances of this entity). I would like to fix that in version 2.0.
So I thought , for version 2.0, lets change the model content so now the properties in all instances of this entity will contain the correct values. So I modified the store (didn't change the model version of scheme ) so it contain the right values.
Here is the problem , If i install version 2.0 on a device that never had version 1.0 , I can see the correct values inside the app and everything is ok. BUT , if I install version 2.0 on top of version 1.0 (update) , The app still show me the values it shown in version 1.0.
My immediate conclusion was that the new version doesn't migrate data in new version to data in the older version , Infect , I read in apple documentation that the migration is typically done from the old store to the new store. and since the old store contains wrong values , I see it also in the new store.
I came to a conclusion that I have to define a migration such that in version 2.0 , the correct values are stored.
Here is what I tried:
Lightweight migration (staying with the same version model) -> still see values of version 1.0.
Created a new version for he model that has the same scheme , created a mapping model that maps from model 1 to model 2.
2.a. migration using mapping model that specify that the property at the destination is filled with the property of the source -> still see the values of version 1.0.
2.b. migration using mapping model that has no rule for the property -> still see the values of version 1.0
2.c. migration using a mapping model that specify that the property of at the destination is filled with the property of the destination -> still see the values of version 1.0
2.d. light weight migration -> still…
I use the following code to initiate a migration:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];