Question

been banging my head.

I added a new model version for my database for migration and added a new attribute but when I run the app without deleting it I get

Can't find model for source store . I tried to debug and noticed that the persistent store can't get created.

I have all the migration stuff set up but I can't figure out why it cannot create the persistent store.

The error seems to point out to my model not being present and I tried to debug and I can see that it gets created and the model is under the documents folder. Any help would be greatly appreciated. I am also using restkit.

Cheers.

Was it helpful?

Solution

You need to delete previous incompatible persistant file. Code below worked for me:

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
            [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
            [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error];
}

OTHER TIPS

If you want to migrate your database without deleting it, and only did small changes on the models (Like adding an attribute), use the following :

[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
                                          configuration:nil
                                                    URL:storeURL
                                                options:@{NSMigratePersistentStoresAutomaticallyOption: @(YES), NSInferMappingModelAutomaticallyOption: @(YES)}
                                                  error:&error];

The key being the options NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top