Objective c 持久存储迁移失败缺少源托管对象模型

Objective c 持久存储迁移失败缺少源托管对象模型,objective-c,cocoa,core-data,Objective C,Cocoa,Core Data,我正在努力扩展我的核心数据。因此,我向实体添加了一个新属性,并尝试使用。但是当我启动程序时,会弹出错误持久存储迁移失败缺少源代码管理的对象模型 谁知道哪里出了问题 我的AppDelegate.c的相关部分(实际上我只添加了NSDictionary*选项): 您需要使用一个版本化的托管对象模型,其中包含模型的两个版本。自动迁移仍然需要查看模型的现有版本和新版本,以便找出差异以及如何处理它们 您引用的错误表明,您的应用程序包现在只包含您的新型号(您要使用的型号),而不包含旧型号(您正试图从中迁移的型

我正在努力扩展我的核心数据。因此,我向实体添加了一个新属性,并尝试使用。但是当我启动程序时,会弹出错误
持久存储迁移失败缺少源代码管理的对象模型

谁知道哪里出了问题

我的AppDelegate.c的相关部分(实际上我只添加了
NSDictionary*选项
):


您需要使用一个版本化的托管对象模型,其中包含模型的两个版本。自动迁移仍然需要查看模型的现有版本和新版本,以便找出差异以及如何处理它们


您引用的错误表明,您的应用程序包现在只包含您的新型号(您要使用的型号),而不包含旧型号(您正试图从中迁移的型号)。回到您的版本控制系统,检索旧模型,然后设置一个版本化模型,其中旧模型为v1,新模型为v2。

我认为,不必使用两个模型。所以你是对的,只有一个模型。也许第一个答案中推荐的那本书会把光明带进黑暗。@lueda:我有,它有。你需要两种型号。Wohoo现在可以用了。正如你所说的,我需要一个版本化的模型,里面有两个模型。这本书完成了其余的工作:)这里有一个问题:使用Xcode4,您似乎无法轻松地设置版本模型并从Finder添加版本。拖放被拒绝。
- (NSPersistentStoreCoordinator *) persistentStoreCoordinator {


    if (persistentStoreCoordinator) return persistentStoreCoordinator;

    NSManagedObjectModel *mom = [self managedObjectModel];
    if (!mom) {
        NSAssert(NO, @"Managed object model is nil");
        NSLog(@"%@:%@ No model to generate a store from", [self class], _cmd);
        return nil;
    }  

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *applicationSupportDirectory = [self applicationSupportDirectory];
    NSError *error = nil;

    if ( ![fileManager fileExistsAtPath:applicationSupportDirectory isDirectory:NULL] ) {
            if (![fileManager createDirectoryAtPath:applicationSupportDirectory withIntermediateDirectories:NO attributes:nil error:&error]) {
            NSAssert(NO, ([NSString stringWithFormat:@"Failed to create App Support directory %@ : %@", applicationSupportDirectory,error]));
            NSLog(@"Error creating application support directory at %@ : %@",applicationSupportDirectory,error);
            return nil;
            }  
    }  

    NSURL *url = [NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"stats.darx"]];
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: mom];
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
                                                configuration:nil 
                                                URL:url 
                                                options:options 
                                                error:&error]){
        [[NSApplication sharedApplication] presentError:error];
        [persistentStoreCoordinator release], persistentStoreCoordinator = nil;
        return nil;
    }   

    return persistentStoreCoordinator;
}