I'm having a problem trying to upgrade an existing store of a Core Data database to a newer model that simply has 1 additional attribute property in an entity. This is not a document based app. Also, not sure if this is significant, but the xcdatamodel and all related files are stored in a framework.

First off, the code for setting my store URL is the following (hope this is readable):

_objectModel = [NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:[NSBundle bundleForClass:[self class]]]]; _dataStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:_objectModel];
BOOL newDatabase = NO;
_storeURL = [storeURL retain];
if([[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]] == NO)
{
        newDatabase = YES;
}
NSError* error = nil;
NSDictionary *optionsDictionary =[NSDictionary dictionaryWithObject: [NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
[_dataStoreCoordinator addPersistentStoreWithType:NSXMLStoreType
                                    configuration:nil
                                              URL:_storeURL
                                          options:optionsDictionary
                                            error:&error];
if(error)
{
        NSLog(@"Error while adding persistent store: %@",error);
}
_context = [[NSManagedObjectContext alloc] init];
[_context setPersistentStoreCoordinator:_dataStoreCoordinator];
_dataStore = [_dataStoreCoordinator persistentStoreForURL:_storeURL];
_loaded = YES;
if(newDatabase)
{
        [_context save:&error];
}       

I tried to go about this two different ways. One was was to include only the newer model file and the mapping file to the build. However, the error I get is:

Error while adding persistent store: Error Domain=NSCocoaErrorDomain Code=134140 UserInfo=0x3c9030 "Persistent store migration failed, missing mapping model."

However, when I include all three files (both model and the mapping), it seems like it's trying to merge the two and ignore the mapping file altogether. The error I get is:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't merge models with two different entities named 'SomePrivateEntityName''

At first I thought it might have been the first line in my code that's trying to do the merging. However, when I try to initialize the ManagedObjectModel with [[NSManagedObjectModel alloc] initWithContentsOfURL:[NSURL URLWithString:@"thePath"]], it gives me the following error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'

I'm about 85% sure I specified the path right, but not sure if that'll actually fix my problem.

Any guidance or suggestions would be appreciated.

Thanks,

Vadim Lozko

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to