1
votes

I want to do migration with 2 CoreData databases. I have read apple developer document.

For the first database, I added some attributes (string, integer and date properties) to new version of database. And following all steps, I have done migration successfully with the first one.

But the second database, I also added attributes (string, integer, date, transformable and binary-data properties) to new version of database. And following all steps (like with the first database) the system returns an error (134130).

Here is the code:

if (persistentStoreCoordinator_) {
    PMReleaseSafely(persistentStoreCoordinator_);
}

// Notify
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:GCalWillMigrationNotification object:self];

//
NSString *sourceStoreType = NSSQLiteStoreType;
NSString *dataStorePath = [PMUtility dataStorePathForName:GCalDBWarehousePersistentStoreName];
NSURL *storeURL = [NSURL fileURLWithPath:dataStorePath];
BOOL storeExists = [[NSFileManager defaultManager] fileExistsAtPath:dataStorePath];

//
NSError *error = nil;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                        [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                        [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];
[persistentStoreCoordinator_ addPersistentStoreWithType:sourceStoreType
                                          configuration:nil
                                                    URL:storeURL
                                                options:options
                                                  error:&error];
if (error != nil) {
    abort();
}

Error is not nil and below is log:

Error Domain=NSCocoaErrorDomain Code=134130 "The operation
couldn\u2019t be completed. (Cocoa error 134130.)" UserInfo=0x856f790
{URL=file://localhost/Users/greensun/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/D10712DE-D9FE-411A-8182-C4F58C60EC6D/Library/Application%20Support/XXX/XXX.sqlite,
metadata={type = immutable dict,
count = 7, entries =>   2 : {contents =
"NSStoreModelVersionIdentifiers"} = {type = immutable, count = 1, values = (    0 : {contents = ""} )}    4 : {contents = "NSPersistenceFrameworkVersion"} = {value = +386, type = kCFNumberSInt64Type}    6 :
{contents =
"NSStoreModelVersionHashes"} = {type = immutable dict, count = 2, entries =>   0 :
{contents = "XXX"} = {length = 32, capacity = 32, bytes =
0xfdae355f55c13fbd0344415fea26c8bb ... 4c1721aadd4122aa}    1 :
{contents = "XXX"} = {length = 32, capacity = 32, bytes =
0x7676888f0d7eaff4d1f844343028ce02 ... 040af6cbe8c5fd01} }  7 :
{contents = "NSStoreUUID"} = {contents =
"51678BAC-CCFB-4D00-AF5C-8FA1BEDA6440"}     8 : {contents = "NSStoreType"} = {contents = "SQLite"}   9 : {contents = "_NSAutoVacuumLevel"} = {contents = "2"}    10 : {contents = "NSStoreModelVersionHashesVersion"} =
{value = +3, type =
kCFNumberSInt32Type} }, reason=Can't find model for source store}

I tried a lot of solutions, but it does not work. I just add more attributes to 2 new version database, and succeed in migrating once.

1

1 Answers

1
votes

This is a bug in Apple framework in iOS5. I assume you are a member of Apple iOS Developer Program, so you can read about it here in Apple Developer Forums.

In short it means that if you have more than one model as you do with two persistent stores for example (but not only then), you cannot in some occasions add a new version of one data model while other models remain at their current versions.

It has been submitted to Apple and marked as duplicate. I do not know if this has been fixed in iOS6 yet.