core data NSPersistentStore issue
Asked Answered
W

2

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 ?

Wilmott answered 28/4, 2014 at 5:57 Comment(2)
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];Madewell
Yes we are adding option directory before the persistent store.Wilmott
W
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.

Wilmott answered 15/5, 2014 at 9:25 Comment(0)
M
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.

Maryellen answered 28/4, 2014 at 14:36 Comment(4)
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?.Merchantman
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.Maryellen
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)'".Wilmott
@Wilmott Please update your question with the exact text of the error. And show your Core Data stack creation code. Thank youMaryellen
W
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.

Wilmott answered 15/5, 2014 at 9:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.