我正在尝试更新一个实现核心数据存储的应用程序。我正在向其中一个实体添加一个属性。
我将以下代码添加到我的委托类中:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Shoppee.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
NSLog(@"Error: %@",error);
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
这来自以下网址:Doc
在执行代码时,我得到了以下错误:
2009-12-01 20:04:22.877
商店25633:207错误:错误
Domain=NSCocoaErrorDomain Code=134130
UserInfo=0x1624d20“操作无法完成。(Cocoa 134130.)“2009-12-01 20:04:22.879 Shoppee25633:22.879 Unresolved error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x1624d20”操作无法完成。NSStoreModelVersionHashesVersion = 3;NSStoreModelVersionIdentifiers =( );NSStoreType = SQLite;NSStoreUUID = "8DC65301-3BC5-42BE-80B8-E44577B8F8E1";};原因=“找不到源店模型”;}
看起来我需要以某种方式包含原始数据模型,但我不确定如何做到这一点。有什么建议吗?
发布于 2011-12-03 07:00:15
重述/完整指南:
在Xcode4中:选择您的.xcdatamodel
->编辑器-> Add Model Version。
在Xcode3中:设计->数据模型->添加模型版本。
您将看到在您的.xcdatamodeld
文件夹中创建了一个新的模式(如果您已经创建了您的新模式,并根据the documentation.
.xcdatamodel
。在选择.xcdatamodeld
文件夹的情况下:
在Xcode4:实用工具侧栏->文件检查器-> Versioned核心数据模型->中,选择新模式。
在Xcode3中: Design > Data Model > Set Current Version。
.xcdatamodel
图标上的绿色标记将移动到新的schema.
在创建NSPersistentStoreCoordinator
的位置(通常是AppDelegate类),对于options
参数,将nil
替换为以下代码:
[NSDictionary dictionaryWithObjectsAndKeys: NSNumber numberWithBool:YES,NSMigratePersistentStoresAutomaticallyOption,NSNumber numberWithBool:YES,NSInferMappingModelAutomaticallyOption,nil]
要点:不会删除旧的模型版本/模式。核心数据需要旧版本迁移到新版本。
发布于 2009-12-02 09:35:48
我想通了。
设计>数据模型>添加模型版本
发布于 2010-06-28 04:34:51
对于Googler,这是你需要做的(假设你已经设置了轻量级迁移):
在进行更改之前,请设计应用程序数据模型并添加模型版本(您将看到在您的应用程序folder)
中创建了一个新的应用程序
第1步是实现这一目标的关键。我遇到这个问题是因为我按照以下步骤添加了一个新字段。这招奏效了。我添加了第二个新字段,但忘记了“添加模型版本”,然后事情就爆炸了。
https://stackoverflow.com/questions/1830079
复制相似问题