使用核心数据时出现问题
我在我的可可应用程序中使用核心数据框架,我创建了几个实体并使用 NSEntityDescription 创建了引用。当我运行应用程序时,收到一条错误消息,指出“用于打开持久存储的托管对象模型版本与用于创建持久存储的版本不兼容”。
Am using core data framework in my cocoa application,I have created couple of entities and created reference using NSEntityDescription. When i run the application am getting an error saying that "The managed object model version used to open the persistent store is incompatible with the one that was used to create the persistent store."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要从设备/模拟器中删除应用程序,然后再次构建并运行。
每次更改模型时都会发生这种情况,因为旧数据存储将保留在应用程序文档文件夹中,而访问它的类已更改。
在开发的后期阶段,您可能希望引入商店迁移,这样您的测试人员和用户就不必在每次发布新版本时删除他们的数据。如果您的模型保持静态,则无需在将来的更新期间迁移数据。
您可能想查看核心数据迁移编程指南了解更多信息。
You need to delete the application from your device / simulator, then build and run again.
This will happen each time you change your model, because the old data store will remain in the apps documents folder, while the classes accessing it have been altered.
In a later stage of development, you will propably want to introduce store migration, sou your testers and users won't have to delete their data each time a new version is released. If your model remains static though, you don't need to migrate the data during future updates.
You might want to take a look at the Core Data Migration Programming Guide for further information.
答案有点棘手,但这对我来说总是有效。这是为了全新安装新的兼容.sqlite 文件,不是迁移!
启动模拟器,删除应用程序和数据(删除应用程序后弹出窗口)。
退出模拟器
打开 X-Code,对数据模型进行任何编辑后
删除
{*appname*}.sqlite
文件(或备份它,从项目文件夹中删除它,然后删除引用)清理app (
Product > Clean
)在模拟器中运行应用程序(对于本教程,我将假设 4.2)
当模拟器运行时,在 Finder 窗口中,导航到:
{*home*} >图书馆>应用支持> iPhone模拟器> 4.2>应用领域>> {*随机标识符*}>文件> {*appname*}.sqlite
复制此文件到另一个位置
停止在 X-Code 中运行您的应用
将 {appname}.sqlite 文件拖放到X 代码中的文件列表。
在弹出的对话框中,确保选中
复制到文件夹
复选框。产品> Clean
然后再次在模拟器中运行应用程序
现在您应该有一个可用的 sqlite 文件!
干杯,
罗伯特
The answer is a bit tricky but this always works for me. This is for a clean installation of a new compatible .sqlite file, not a migration!
launch simulator, delete the app and the data (the popup after you delete the app).
quit simulator
open X-Code, after making any edits to your data model
delete the
{*appname*}.sqlite
file (or back it up, remove it from project folder, and delete reference)clean the app (
Product > Clean
)Run the app in a simulator (for this tutorial I will assume 4.2)
While the simulator is running, in a Finder window, navigate to:
{*home*} > Library > Application Support > iPhone Simulator > 4.2 > Applications > {*random identifier*} > Documents > {*appname*}.sqlite
Copy this file to another location
Stop running your app in X-Code
Drag and drop the {appname}.sqlite file into the files list in X-Code.
In the dialog that pops up, make sure the
copy to folder
checkbox, is checked.Product > Clean
Then run the app in the simulator again
Now you should have a working sqlite file!
Cheers,
Robert
您必须从以下位置删除持久存储文件:
~/Library/$AppName
~/Library/Application Support/$AppName
(取决于您的 Xcode 版本。)
You must delete the persistent store file from either:
~/Library/$AppName
~/Library/Application Support/$AppName
(Depending on your version of Xcode.)