0

我用核心数据构建了我的应用程序。它适用于具有两个属性的实体。当我想添加具有单个属性的新实体时,我的应用程序在启动时崩溃。

2012-07-16 23:11:13.579 myApp[6773:fb03] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x6bb36e0 {metadata=<CFBasicHash 0x6bbae90 [0x1748b48]>{type = immutable dict, count = 7,
entries =>
    2 : <CFString 0x6bbab30 [0x1748b48]>{contents = "NSStoreModelVersionIdentifiers"} = <CFArray 0x6bbaf20 [0x1748b48]>{type = immutable, count = 1, values = (
    0 : <CFString 0x1743cd8 [0x1748b48]>{contents = ""}
)}
    4 : <CFString 0x6bbab60 [0x1748b48]>{contents = "NSPersistenceFrameworkVersion"} = <CFNumber 0x6bbaa30 [0x1748b48]>{value = +386, type = kCFNumberSInt64Type}
    6 : <CFString 0x6bbaec0 [0x1748b48]>{contents = "NSStoreModelVersionHashes"} = <CFBasicHash 0x6bbafb0 [0x1748b48]>{type = immutable dict, count = 1,
entries =>
    2 : <CFString 0x6bbaf40 [0x1748b48]>{contents = "AllFamille"} = <CFData 0x6bbaf60 [0x1748b48]>{length = 32, capacity = 32, bytes = 0x5a5b78eb9edf4005bbe8a8d5e85fd102 ... 208bdf48b8b44695}
}

    7 : <CFString 0x1101ad8 [0x1748b48]>{contents = "NSStoreUUID"} = <CFString 0x6bbad30 [0x1748b48]>{contents = "45640157-116E-4616-93C5-2DA6027F4E9C"}
    8 : <CFString 0x1101978 [0x1748b48]>{contents = "NSStoreType"} = <CFString 0x1101988 [0x1748b48]>{contents = "SQLite"}
    9 : <CFString 0x6bba9e0 [0x1748b48]>{contents = "_NSAutoVacuumLevel"} = <CFString 0x6bbb000 [0x1748b48]>{contents = "2"}
    10 : <CFString 0x6bbaef0 [0x1748b48]>{contents = "NSStoreModelVersionHashesVersion"} = <CFNumber 0x6d84b60 [0x1748b48]>{value = +3, type = kCFNumberSInt32Type}
}
, reason=The model used to open the store is incompatible with the one used to create the store}, {
    metadata =     {
        NSPersistenceFrameworkVersion = 386;
        NSStoreModelVersionHashes =         {
            AllFamille = <5a5b78eb 9edf4005 bbe8a8d5 e85fd102 3c6d4040 f1b7fc6c 208bdf48 b8b44695>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "45640157-116E-4616-93C5-2DA6027F4E9C";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "The model used to open the store is incompatible with the one used to create the store";
}
4

2 回答 2

5

可能是因为您添加了该属性。因此,您的新数据库与旧数据库不一致。尝试删除模拟器文件夹下的数据库并再次运行。

于 2012-07-16T21:19:37.480 回答
2

发生此问题是因为用于保存数据库的托管对象模型不同,因为您添加了新实体,因此修改后的托管对象模型不能用于加载使用前一个模型保存的数据。

如果您正在使用数据库的第一个版本,则可以从模拟器/设备中删除该应用程序。但是,如果您要更改已发布的应用程序,这可能会变成一个大问题,因为您不能要求用户在安装新版本之前卸载您的应用程序。

在这种情况下,您应该创建一个新版本的托管对象模型,然后配置 Core Data 以在您的数据库上执行从以前的模型版本到最新版本的轻量级迁移。

请按照文档中详细说明的步骤进行操作

于 2012-07-19T21:41:32.343 回答