Take the 2-minute tour ×

I have hit a brick wall trying to setup lightweight migration of Core Data using MagicalRecord. I have looked at all of the posts on this subject, using Google and SO. I understand how the persistentStoreCoordinator works and what the settings I am trying to make also do.

Here's my code:


NSPersistentStoreCoordinator *persistentStoreCoordinator;


- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

if (persistentStoreCoordinator != nil) {
    return persistentStoreCoordinator;

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"saori.sqlite"]];

// handle db upgrade
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

NSError *error = nil;


    // Handle error

return persistentStoreCoordinator;


I'm getting the following errors, which I understand; what I don't know is where are these objects (I have looked in my app, and found nothing):

No visible @interface for 'AppDelegate' declares the selector 'applicationDocumentsDirectory' and

No visible @interface for 'AppDelegate' declares the selector 'managedObjectModel'

I have already created the stores:


Most, if not all of the code I have looked at is similar; I don't know if MagicalRecord handles this for me or not because I can't find any docs that would indicate how to do this using MR. My question is: what do I have to do to make this work?

share|improve this question
In your last screenshot, the new model hasn't been made the active one yet, so the old model will still be used. –  Scott Berrevoets May 30 '13 at 16:43

2 Answers 2

up vote 7 down vote accepted

The whole point of MagicalRecord is that this is managed for you:

[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:####];

Check the docs about the Core Data stack setup here.

share|improve this answer
Yes, I read that, but didn't realize MR would do everything for me! I had your bit of code already; thank you... One more question: if I do NOT use the DEBUG flag, but rather create the new model myself, will MR still find it, or is using the DEBUG flag the way to notify MR it needs to do the migration? If that is the case, how do I handle this when the app is in the AppStore? –  spokane-dude May 30 '13 at 16:48
The migration is handled by passing certain flags to Core Data. This causes Core Data to check the model versions that are available and use those to automatically detect and fix the differences. –  Wain May 30 '13 at 17:00
MagicalRecord will load all the models in your bundle and merge them together, unless there are multiple versions of the same model, and then it'll merge only the latest version with the others. This is the default Core Data behavior in the +[NSManagedObjectModel managedObjectModelsFromBundle:] method, which is what MagicalRecord also uses to load the models. –  casademora May 30 '13 at 17:17
That link appears to be dead now, and there doesn't seem to be a replacement. :( –  ray Aug 26 '13 at 16:29

As of my understanding of the question, i suggest you to use this

[MagicalRecord setupAutoMigratingCoreDataStack]

If you have not changed the model version, change it to new model created from the old model

share|improve this answer

Your Answer


