iPhone Managed Objects – Can’t find model for source store

If you get an error reason in manage objects as follows:

” Can’t find model for source store “

this means that either your object model and generated/coded model codes are out of sync or your db is not migrated/upgraded correctly to the new version. When you have many models with many relationships, it may be difficult to spot the issue. The easy way resolve this issue is to regenerate all the code.

Following is the code to create options on the store context to migrate automatically to new version of db.

NSDictionary *optionsForSTore = [NSDictionary dictionaryWithObjectsAndKeys: 

        [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,

        [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

You can delete the whole db so that you do not have this issue. However, you will loose all the data.

I have spent many hours to find easier way to trace this issue. As the compiler does not catch the mis-match in the model-code and there is not much feedback on error on the managed objects, this becomes a mysterious issue.

The easiest way to avoid this issue is always regenerate the entity that you are modifying and have the options set in the managed context.