2011-08-03 26 views
4

我已經看到這個問題張貼在這裏,但總是,答案是模型已被改變,重置模擬器,刪除商店。可可錯誤134100再次 - (用於打開模型是從用於創建模型不兼容)

我也收到這個錯誤,但是,這是一個新的應用程序。我沒有添加/更改實體或屬性。

我已經刪除了商店,我重置了模擬器,但我得到了相同的結果。

這裏是商店代碼..是否有任何其他原因導致此問題?

- (NSManagedObjectModel *)managedObjectModel { 
    // NSLog(@"%s", __FUNCTION__); 
    if (managedObjectModel_ != nil) { 
     return managedObjectModel_; 
    } 

    NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Lexicon" ofType:@"momd"]; 
    NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; 
    managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];  
    return managedObjectModel_; 
} 

/** 
Returns the persistent store coordinator for the application. 
If the coordinator doesn't already exist, it is created and the application's store added to it. 
*/ 
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 

    if (persistentStoreCoordinator_ != nil) { 
     return persistentStoreCoordinator_; 
    } 

    NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"dict.sqlite"]]; 

    NSError *error = nil; 
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 

     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    }  

    return persistentStoreCoordinator_; 
} 

這裏是控制檯噴涌:

2011-08-03 11:42:38.936詞典[4468:F203] - [AppDelegate中 應用中:didFinishLaunchingWithOptions:] 2011-08-03 11 :42:38.989 Lexicon [4468:f203] - [AppDelegate applicationDocumentsDirectory] ​​ 2011-08-03 11:42:39.048 Lexicon [4468:f203]未解決的錯誤錯誤 Domain = NSCocoaErrorDomain Code = 134100「The operation could not completed。(Cocoa error 134100.)「UserInfo = 0x6d3ee60 {metadata = {type =不可變字典, count = 7,entries => 2:{contents = 「NSStoreModelVersionIdentifiers」} = {type = immutable,count = 1,values =(0:{length = 0,capacity = 0,bytes = 0x} )} 4: {contents = 「NSPersistenceFrameworkVersion」} = {value = +363,type = kCFNumberSInt64Type} 6:{contents =「NSStoreModelVersionHashes」} = {type = immutable dict,count = 1, entries => 0 :{內容= 「LexiconEntity」} = {長度= 32, 容量= 32,字節= 0x8698c5295fa5124b78a6b127bba26ff0 ... 70eaece0517cd4c6}}

7:{內容= 「NSStoreUUID」} = {內容=「內容=」SQLite「} 9:{內容=」_NSAutoVacuumLevel「} = {內容=」2「} 10:{內容=」2「} {內容= 「NSStoreModelVersionHashesVersion」} = {值= 3,類型= kCFNumberSInt32Type}},原因=用來打開存儲該模型是 與用於創建存儲}的一個不兼容,{ 元數據= { NSPersistenceFrameworkVersion = 363; NSStoreModelVersionHheshes = { LexiconEntity = < 8698c529 5fa5124b 78a6b127 bba26ff0 f3bc678b a4f1e809 70eaece0 517cd4c6>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers =( <> ); NSStoreType = SQLite; NSStoreUUID =「86B22D58-28A5-4585-8650-07111B34B43A」; 「_NSAutoVacuumLevel」= 2; }; reason =「用於打開商店的模型與用於創建商店的模型不兼容 」; }

回答

2

事實證明,sqlite數據庫存儲建立不正確。所以,在這種情況下,信息是相當準確的。

上述問題是真實的。該數據庫沒有反映該模型。

解決方案是讓Core Data從模型創建空數據庫,然後讓Core Data自己導入數據。

我第一次將我的sqlite數據庫導出到調用文件db.sql(imaginative!)的sql中。我只導出了數據表和主鍵表,而不是元數據表。我爲此使用了一個名爲SQLiteManager的應用程序。您也可以在命令行中執行此操作。

所有的代碼是股票的東西,除了用於處理持久性存儲控制器..

該代碼如下:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 

    if (persistentStoreCoordinator_ != nil) { 
     return persistentStoreCoordinator_; 
    } 


    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"db.sql"]; 

    // set up the backing store 
    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    // If the expected store doesn't exist, copy the default store. 
    if (![fileManager fileExistsAtPath:storePath]) { 
     NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"dict" ofType:@"sqlite"]; 
     if (defaultStorePath) { 
      [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL]; 
     } 
    } 

    NSURL *storeURL = [NSURL fileURLWithPath:storePath]; 

    NSError *error = nil; 
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
    if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { 

     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    }  

    return persistentStoreCoordinator_; 
} 

我希望這有助於..這似乎爲我工作..

相關問題