7

I am developing an application that is rolled out in stages. For each sprint, there are database changes so core data migration has been implemented. So far we have had 3 stage releases. Whenever successive up gradation is done , the application runs fine. But whenever I try to upgrade from version 1 to version 3, 'unable to add persistent store' error occurs'. Can someone help me with the issue ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mary
  • 335
  • 4
  • 14
  • If it is lightweight migration, are you passing the options dictionary before add persistent store? where the dictionary is [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; – Adithya Apr 28 '14 at 06:06
  • Yes we are adding option directory before the persistent store. – Mary Apr 28 '14 at 08:43

2 Answers2

5

Core Data migration does not have a concept of versions as you would expect them. As far as Core Data is concerned there are only two versions, the version of the NSPersistentStore and the version you are currently using.

To use lightweight migration, you must test every version of your store and make sure that it will migrate to the current version directly. If it does not then you cannot use lightweight migration for that specific use case and you either need to develop a migration model or come up with another solution.

Personally, on iOS, I avoid heavy migration as it is very expensive in terms of memory and time. If I cannot use a lightweight migration I most often will explore export/import solutions (exporting to JSON for example and importing in to the new model) or look at refreshing data from the server.

Marcus S. Zarra
  • 46,571
  • 9
  • 101
  • 182
  • Are you saying that if I have 3 versions A, B and C, and I test lightweight migration A to B, and B to C, the migration A to C is not 100% safe?. I never heard something like that, could you make a sample to demonstrate it?. – Daniele Apr 28 '14 at 17:39
  • 1
    No I will not make a sample to demonstrate it. And yes you need to test every possibility. If you are on C now you need to test A to C and B to C. The details of it are covered in my book and in Apple's documentation. The versioning is not temporal. There is only Old/New. – Marcus S. Zarra Apr 28 '14 at 18:11
  • when i am trying to update from A to c ,then i got an error "erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to add persistent store (null)'". – Mary Apr 29 '14 at 11:17
  • @Mary Please update your question with the exact text of the error. And show your Core Data stack creation code. Thank you – Marcus S. Zarra Apr 29 '14 at 14:05
1

My problem is i am trying to change my attribute datatype during automatic lightweight migration, as automatic lightweight core data migration does not support data type change. I resolved this issue by resetting the data type to older one.

Mary
  • 335
  • 4
  • 14