一个实体在iOS 8 beta 3中被遗漏

时间:2014-07-23 07:37:34

标签: ios ipad core-data ios8 core-data-migration

您好,我在AppStore中有我的项目,现在我已经为CoreData中的实体数量添加了一些属性,并在persistentStoreCoordinator中添加了迁移代码,我能够在7.1.1中成功运行,我将我的设备更新到iOS 8 beta 3 ,现在我无法打开我的应用程序,我已经使用以下代码进行迁移,并且我收到崩溃报告,请指导我如何解决此问题。

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {


if (_persistentStoreCoordinator != nil) {
    return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Sample/Sample.sqlite"];

NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = @{
                          NSMigratePersistentStoresAutomaticallyOption : @YES,
                          NSInferMappingModelAutomaticallyOption : @YES
                          };    
// Check if we need a migration
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeURL error:&error];
NSManagedObjectModel *destinationModel = [_persistentStoreCoordinator managedObjectModel];
BOOL isModelCompatible = (sourceMetadata == nil) || [destinationModel isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
if (! isModelCompatible) {
    // We need a migration, so we set the journal_mode to DELETE
    options = @{NSMigratePersistentStoresAutomaticallyOption:@YES,
                NSInferMappingModelAutomaticallyOption:@YES,
                NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"}
                };
}
NSPersistentStore *persistentStore = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error];
if (! persistentStore) {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documents = [paths objectAtIndex:0];
    NSString *databasePath = [documents stringByAppendingPathComponent:@"Sample"];
    NSString *sqlite = [databasePath stringByAppendingPathComponent:@"Sample.sqlite"];

    [[NSFileManager defaultManager] removeItemAtPath:sqlite error:nil];

    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
    //abort();
}
// Reinstate the WAL journal_mode
if (! isModelCompatible) {
    [_persistentStoreCoordinator removePersistentStore:persistentStore error:NULL];
    options = @{NSMigratePersistentStoresAutomaticallyOption:@YES,
                NSInferMappingModelAutomaticallyOption:@YES,
                NSSQLitePragmasOption: @{@"journal_mode": @"WAL"}
                };
    [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error];
}
return _persistentStoreCoordinator;

}

崩溃报告是:

Jul 21 13:15:50 Vivians-iPad-air BW - Internal[457] <Warning>: CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/B2114FDE-D2CD-4FC6-B6E1-90CF8F7B71FF/Documents/Boardworks/BoardWorks.sqlite options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
    NSSQLitePragmasOption =     {
        "journal_mode" = DELETE;
    };
} ... returned error Error Domain=NSCocoaErrorDomain Code=134020 "The operation couldn’t be completed. (Cocoa error 134020.)" UserInfo=0x146c5040 {NSUnderlyingException=Can't find table for entity Agenda in database at URL file:///var/mobile/Containers/Data/Application/B2114FDE-D2CD-4FC6-B6E1-90CF8F7B71FF/Documents/Boardworks/BoardWorks.sqlite} with userInfo dictionary {
    NSUnderlyingException = "Can't find table for entity Agenda in database at URL file:///var/mobile/Containers/Data/Application/B2114FDE-D2CD-4FC6-B6E1-90CF8F7B71FF/Documents/Boardworks/BoardWorks.sqlite";

0 个答案:

没有答案