Core Data Automatic Lightweight Migration

15 views
Skip to first unread message

Richard Somers

unread,
Apr 2, 2012, 6:20:46 PM4/2/12
to coco...@lists.apple.com
I am attempting to do a core data automatic lightweight migration. The NSPersistentDocument method -configurePersistentStoreCoordinatorForURL:... is overridden following the instructions found here http://tinyurl.com/87orsnl by Apple and here http://tinyurl.com/755zplp by Marcus Zarra.

- (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:(NSString *)fileType modelConfiguration:(NSString *)configuration storeOptions:(NSDictionary *)storeOptions error:(NSError **)error
{
NSMutableDictionary *options = nil;
if (storeOptions != nil) {
options = [storeOptions mutableCopy];
} else {
options = [[NSMutableDictionary alloc] init];
}

[options setObject:[NSNumber numberWithBool:YES]
forKey:NSMigratePersistentStoresAutomaticallyOption];
[options setObject:[NSNumber numberWithBool:YES]
forKey:NSInferMappingModelAutomaticallyOption];

BOOL result = [super configurePersistentStoreCoordinatorForURL:url
ofType:fileType
modelConfiguration:configuration
storeOptions:options
error:error];
[options release], options = nil;
return result;
}

The resulting behavior is somewhat bizarre.

When opening a xml document, multiple validation errors occur and the document does not open but another document "mydocument.myappxml.new" is created in the same directory as the original. The new unopened document has been correctly migrated.

When opening a sqlite document, the document opens without error but a another document "mydocument~.myappsqlite" is created in the same directory as the original.

Some developers have suggested placing Apple's options dictionary code for the persistent store coordinator in the application delegate. Refer to http://tinyurl.com/7jgknyk But this seems only to work for a specific store type. I need it to for all three store types, xml, sqlite, and binary.

Can anyone shed some light on this? Thanks.

--Richard


_______________________________________________

Cocoa-dev mailing list (Coco...@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:
https://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-garchive-98506%40googlegroups.com

This email sent to cocoa-dev-ga...@googlegroups.com

Richard Somers

unread,
Apr 2, 2012, 7:00:42 PM4/2/12
to coco...@lists.apple.com
On Apr 2, 2012, at 4:20 PM, Richard Somers wrote:

> Can anyone shed some light on this?

It appears that others have also recently experienced frustration with automatic lightweight migration and have come up with zero answers.

Jan 26, 2012

http://stackoverflow.com/questions/9014668/core-data-automatic-lightweight-migration-failing-in-xcode-4-using-process-the-w

Mar 20, 2012

http://stackoverflow.com/questions/9791706/automatic-core-data-migration-fails-on-mac-os-x-10-5-but-not-on-10-6-or-10-7

Jerry Krinock

unread,
Apr 3, 2012, 1:01:28 AM4/3/12
to Cocoa Developers

On 2012 Apr 02, at 15:20, Richard Somers wrote:

> When opening a sqlite document, the document opens without error but a another document "mydocument~.myappsqlite" is created in the same directory as the original.

That is expected behavior. The "tildefied" document, as I call it (tilde = "~") is in fact the old document, prior to migration, which Core Data has renamed. It is an undocumented "feature" of Core Data. Apparently, the idea is that, with help from your Support Department, a distressed user can revert if the migration gave undesired results.

So it looks like your SQLite migration is working correctly. Only your XML migration is failing.

Reply all
Reply to author
Forward
0 new messages