On Feb 8, 2011, at 9:08 PM, Gordon Apple wrote:

> I am trying to migrate an existing app CoreData database to a new version.
> Theoretically, this should be what's called a simple migration.  I have not
> been able to get it to work.  Just to see what it's trying to do, I went
> ahead and let it generate a mapping model, which appears to be correct.  But
> somehow, it is apparently not reading the original database.  The following
> returns nil.
> 
> - (NSPersistentStoreCoordinator*)persistentStoreCoordinator {
>    if (persistentStoreCoordinator != nil)
>        return persistentStoreCoordinator;
> 
>    NSURL *storeUrl = [NSURL fileURLWithPath: [[[self class]
> appStorageDirectory] stringByAppendingPathComponent: @"myApp.sqlite"]];
> 
>    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
>                          [NSNumber numberWithBool:YES],
> NSMigratePersistentStoresAutomaticallyOption,
>                          [NSNumber numberWithBool:YES],
> NSInferMappingModelAutomaticallyOption,
>                          nil];

If you have a Mapping-Model you don't need the 
NSInferMappingModelAutomaticallyOption
(which tries to build a mapping-model on the fly). But I don't think this is 
the problem. 

To get a better understanding where the problem is, I would try to do it 
manually. 
As described in 
<http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmInitiating.html%23//apple_ref/doc/uid/TP40005509-SW3>
 "The default Migration Process": 

- find the model of the original store. Typed in Mail.app: 

id metaData = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType: 
nil URL: storeURL error: &error];
id model = [NSManagedObjectModel mergedModelFromBundles: bundles 
forStoreMetaData: metaData];

should give you the model of the original file. 

- find the mapping model: (newModel is your current model)

id mappingModel = [NSMappingModel mappingModelFromBundles: bundles 
forSourceModel: model destinationModel: newModel];

If this all goes well you can try to migrate using NSMigrationManager ... As 
described as "Manual Migration" in the 
document linked above. Hopefully you get better error messages on the way ....


Cheers, 

Felix

> 

_______________________________________________

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 arch...@mail-archive.com

Reply via email to