2012-06-21 41 views
1

我想用2個CoreData數據庫進行遷移。我已閱讀apple developer document遷移核心數據錯誤代碼134130

對於第一個數據庫,我向新版本的數據庫添加了一些屬性(字符串,整數和日期屬性)。按照所有步驟,我已經成功完成了第一個遷移。

但是第二個數據庫中,我還向新版本的數據庫添加了屬性(字符串,整數,日期,可轉換和二進制數據屬性)。並遵循所有步驟(如第一個數據庫),系統返回一個錯誤(134130)。

下面是代碼:

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 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} 

我嘗試了很多的解決方案,但它不工作。我只是將更多的屬性添加到2個新版本數據庫,併成功遷移一次。

回答

1

這是iOS5中Apple框架中的一個錯誤。我假設你是Apple iOS開發者計劃的成員,所以你可以在Apple Developer Forums這裏閱讀。簡而言之,如果你有兩個以上的持久性存儲(比如不止一個),那麼你就不能在某些情況下添加一個數據模型的新版本,而其他模型仍然在他們目前的版本。

它已提交給Apple並標記爲重複。我不知道這是否已在iOS6中修復。

+0

感謝您回覆我的問題。 – magichero

+0

我已經解決了我的問題。 我一直在使用SVN,當我創建Core Date的新版本時,SVN也創建了舊版本數據的副本。 我不得不在外部複製一個副本,並從項目中刪除SVN中的總體核心數據。然後,我創建新的核心數據並解決了我的問題。 – magichero