CoreData修改了数据模型报错 The model used to open the store is incompatible with the one used to create the store

在iOS 6 – Core Data 应用程序的开发过程中, App启动时出现如下异常信息:

reason = “The model used to open the store is incompatible with the one used to create the store”

出现上述异常的原因是 :我们修改了Data Model文件,增加了新的Entity,包括Attribute属性、Relationship关系等等。

解决办法:

(1) 最简单的办法是,在iOS 5 或者 6的模拟器中,删除App,然后重新运行就可以了。

(2) 第二种办法是使用Data Model 数据模型的版本属性:

给Data Model(也就是被管理对象模型)添加一个新的版本:

  1. 在项目导航栏中,选择Data Model 文件;
  2. 选择 Editor > Create Model Version 菜单项;
  3. 在对话框中,输入Data Model文件的名称,并点击Save按钮;

CoreData修改了数据模型报错 The model used to open the store is incompatible with the one used to create the store

然后设置 Data Model的当前版本号:

  1. 在项目导航栏中,选择Data Model文件;
  2. 在File inspector 面板窗口,找到Versioned Core Data Model 节点;
  3. 从弹出菜单中,选择当前模板版本号;

CoreData修改了数据模型报错 The model used to open the store is incompatible with the one used to create the store