我有一个核心数据EntityDescription,我在其中创建了数据.然后,我更改了EntityDescription,添加了新的,使用编辑器xcdatamodeld文件删除旧的.
现在,我的核心数据代码都会导致此错误"The model used to open the store is incompatible with the one used to create the store}".详情如下.我该怎么办?我更喜欢删除数据模型中的所有内容并重新启动新数据模型.
谢谢你的任何建议!
reason=The model used to open the store is incompatible with the one used to create the store}, {
metadata = {
NSPersistenceFrameworkVersion = 320;
NSStoreModelVersionHashes = {
Promotion = <472663da d6da8cb6 ed22de03 eca7d7f4 9f692d88 a0f273b7 8db38989 0d34ba35>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
);
NSStoreType = SQLite;
NSStoreUUID = "9D6F4C7E-53E2-476A-9829-5024691CED03";
"_NSAutoVacuumLevel" = 2;
};
Run Code Online (Sandbox Code Playgroud)
Vij*_*y S 10
删除应用有时并非如此!建议,您的应用已经发布!您不能只是将新实体添加到数据库并继续 - 您需要执行迁移!
对于那些不想深入了解文档并正在寻找快速修复的人:
打开.xcdatamodeld文件
单击编辑器
选择添加型号版本...
添加模型的新版本(添加了新的数据模型组)
选择主文件,打开文件检查器(右侧面板),在Versioned核心数据模型下选择当前数据模型的新版数据模型
这不是全部)你应该执行所谓的"轻度迁移".
转到AppDelegate并找到正在创建persistentStoreCoordinator的位置
找到这一行 if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
替换nil选项 @{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} (actually provided in the commented code in that method)
在这里,你玩得开心!PS这仅适用于轻量级迁移.要使您的迁移符合轻量级迁移的要求,您的更改必须限制在此窄带:
添加或删除属性(属性或关系).使非可选属性可选.只要提供默认值,就可以选择非可选属性.添加或删除实体.重命名一个属性.重命名实体.
从斯塔斯借来的答案
如果这是非生产应用程序,只需删除本地数据库(appname.sqlite)并重新启动应用程序.
我发现我总是这样做,所以提供以下额外的细节:
在XCode 4(4.3.2)下,您应该在这里找到您的数据存储区:
/ Users /〜/ Library/Application Support/iPhone Simulator/simulatorVersion/Applications/yourAppIdentifier/Documents
或者,如果您首先启用搜索系统文件,则可以使用Spotlight; 我发现将这样的搜索保存到菜单栏最快.
| 归档时间: |
|
| 查看次数: |
15751 次 |
| 最近记录: |