I have had an existing data model with a single persistent store, and all is good.
Now, following the WWDC 2012 video "Using iCloud with Core Data" (#227), I've defined two configurations in my model, "Cloud" and "Local" while keeping the original "Default". I've split my entities between "Cloud" and "Local". In my code, I add just the two corresponding persistent stores:
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @YES,
NSInferMappingModelAutomaticallyOption: @YES};
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:@"Cloud"
URL:[self cloudPersistentStoreURL]
options:options
error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:@"Local"
URL:[self localPersistentStoreURL]
options:options
error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
These are added just fine. Later, when running the app and I try to save some initial trial data as normal, the following exception is thrown:
NSUnderlyingException=Can't resolve how to assign objects to stores; some objects may have been assigned to stores; use [[managedObject objectID] persistentStore] to find out what is going where now; use [managedObjectContext assignObject:toStore:] to straighten things out
I've Googled pieces of this with no hits, and Apple's troubleshooting Core Data document doesn't appear to discuss this. I have no clue what can be causing this or where to look. Any thoughts?
Ensure that you have no relationships crossing from one store into another. Related entities must be located inside the same configuration.
For example you have entity Book
configured to be stored in Cloud
and Author
to be stored into Local
. Both are related.
When you now assign an Author
to a Book
and save, then CoreData cannot handle the relationship and will raise the error you are seeing.