因此,我发生了一次奇怪的崩溃,希望有人可以读取崩溃数据。大约一个月前,我为一个应用程序构建了Core Data模型。它是12个实体,每个实体与其他实体都有几种关系。大约两个星期前(试飞之后),我想更新模型。我对模型进行了版本控制,将两个标志(NSMigratePersistentStoresAutomaticallyOption,NSInferMappingModelAutomaticallyOption)添加到了persistentStoreCoordinator的创建中,并进行了更改。我启动了应用程序,模型已迁移,我正在路上。从那时起,我毫无困难地对数据模型的版本2进行了其他更改。今天,我向一个实体添加了一个布尔属性,现在该应用在启动时崩溃。如果删除新添加的属性,则该应用程序可以正常运行。我正在努力了解过去两周中我如何轻松地向版本2添加属性,实体甚至关系。这是布尔标志吗?任何指导,不胜感激。这是崩溃日志:

2015-03-18 22:01:16.778 GroupShop [67338:2060644] CoreData:错误:-addPersistentStoreWithType:SQLite配置:(空)URL:文件:/// Users / tom / Library / Developer / CoreSimulator / Devices / 0FD3C702- 3CB8-49AA-AA22-72FED2328608 /数据/容器/数据/应用程序/ 37785998-3FC9-4C96-ADD4-920BAAB1CCFD /文档/store.data选项:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
} ...返回错误Error Domain = NSCocoaErrorDomain代码= 134130“操作无法完成。(可可错误134130。)” UserInfo = 0x7fb9733d86e0 {URL = file:/// Users / tom / Library / Developer / CoreSimulator /设备/ 0FD3C702-3CB8-49AA-AA22-72FED2328608 /数据/容器/数据/应用/ 37785998-3FC9-4C96-ADD4-920BAAB1CCFD /文档/store.data,元数据= {
    NSPersistenceFrameworkVersion = 519;
    NSStoreModelVersionHashes = {
        GSFullImage = ;
        GSGroupShop = ;
        GSInvites = ;
        GSItem = ;
        GSItemCategory = ;
        GSLocation = ;
        GSMembers = ;
        GSMessageText = ;
        GSNotificationDetail = ;
        GSOpinion = ;
        GSPermissions = ;
        GSShoppingItems = ;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =(
        ”
    );
    NSStoreType = SQLite;
    NSStoreUUID =“ B8C295E3-8527-4438-BB39-6CBAFAF97194”;
    “ _NSAutoVacuumLevel” = 2;
},reason =找不到userstore字典{
    URL =“ file:/// Users / tom / Library / Developer / CoreSimulator / Devices / 0FD3C702-3CB8-49AA-AA22-72FED2328608 / data / Containers / Data / Application / 37785998-3FC9-4C96-ADD4-920BAAB1CCFD / Documents /存储数据”;
    元数据= {
        NSPersistenceFrameworkVersion = 519;
        NSStoreModelVersionHashes = {
            GSFullImage = ;
            GSGroupShop = ;
            GSInvites = ;
            GSItem = ;
            GSItemCategory = ;
            GSLocation = ;
            GSMembers = ;
            GSMessageText = ;
            GSNotificationDetail = ;
            GSOpinion = ;
            GSPermissions = ;
            GSShoppingItems = ;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =(
            ”
        );
        NSStoreType = SQLite;
        NSStoreUUID =“ B8C295E3-8527-4438-BB39-6CBAFAF97194”;
        “ _NSAutoVacuumLevel” = 2;
    };
    原因=“找不到源存储的模型”;
}
2015-03-18 22:01:16.781 GroupShop [67338:2060644] CoreData:注释:NSPersistentStoreCoordinator的当前模型散列为{
    GSFullImage = ;
    GSGroupShop = ;
    GSInvites = ;
    GSItem = ;
    GSItemCategory = ;
    GSLocation = ;
    GSMembers = ;
    GSMessageText = ;
    GSNotificationDetail = ;
    GSOpinion = ;
    GSPermissions = ;
    GSShoppingItems = ;
}
2015-03-18 22:01:16.831 GroupShop [67338:2060644] ***由于未捕获的异常“打开失败”而终止了应用程序,原因:“原因:操作无法完成。 (可可错误134130。)'
***首先抛出调用堆栈:

    0 CoreFoundation 0x000000010ce84a75 __exceptionPreprocess + 165
    1 libobjc.A.dylib 0x000000010bfe2bb7 objc_exception_throw + 45
    2 CoreFoundation 0x000000010ce849ad + [NSException提高:格式:] + 205
    3 GroupShop 0x000000010b416813-[GSDataAccess initPrivate] + 867
    4 GroupShop 0x000000010b416472 __32 + [GSDataAccess sharedDataAccess] _block_invoke + 50
    5 libdispatch.dylib 0x00000001107fb614 _dispatch_client_callout + 8
    6 libdispatch.dylib 0x00000001107e7881 dispatch_once_f + 565
    7 GroupShop 0x000000010b41641d + [GSDataAccess sharedDataAccess] + 141
    8 GroupShop 0x000000010b3a7066-[GSUtility initSimple] + 182
    9 GroupShop 0x000000010b3a6f72 __26 + [GSUtility sharedUtility] _block_invoke + 50
    10 libdispatch.dylib 0x00000001107fb614 _dispatch_client_callout + 8
    11 libdispatch.dylib 0x00000001107e7881 dispatch_once_f + 565
    12 GroupShop 0x000000010b3a6f1d + [GSUtility sharedUtility] + 141
    13 GroupShop 0x000000010b3b20e5-[AppDelegate应用程序:didFinishLaunchingWithOptions:] + 581
    14 UIKit 0x000000010ddf3458-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
    15 UIKit 0x000000010ddf4002-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2540
    16 UIKit 0x000000010ddf6e3e-[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
    17 UIKit 0x000000010ddf5d35-[UIApplication WorkspaceDidEndTransaction:] + 179
    18 FrontBoardServices 0x0000000112728243 __31- [FBSSerialQueue performAsync:] _ block_invoke + 16
    19 CoreFoundation 0x000000010cdb9c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    20 CoreFoundation 0x000000010cdaf9c5 __CFRunLoopDoBlocks + 341
    21 CoreFoundation 0x000000010cdaf183 __CFRunLoopRun + 851
    22 CoreFoundation 0x000000010cdaebc6 CFRunLoopRunSpecific + 470
    23 UIKit 0x000000010ddf57a2-[UIApplication _run] + 413
    24 UIKit 0x000000010ddf8580 UIApplicationMain + 1282
    25 GroupShop 0x000000010b408033主+

最佳答案

您不能一直更改相同的模型版本并期望Core Data保持更新。您使用的迁移选项仅在数据与当前模型版本不匹配但与应用程序中包含的某些较旧版本匹配时才适用。通过自动的轻量级迁移,Core Data可以找出如何更新持久性存储以使用新模型。如果更改相同版本的模型,则可能会阻止Core Data将持久性存储文件与任何模型版本进行匹配,然后会出现此异常。

您提到您进行了一些更改并且成功了。并非所有更改都会影响模型的版本哈希。核心数据模型由[NSEntityDescription versionHash]返回的其实体的版本哈希唯一标识。这又取决于versionHashNSRelationshipDescriptionNSAttributeDescriptionNSPropertyDescription的值的结果。一些较小的更改不会影响任何版本哈希。通常,更改不会影响版本哈希,除非它们影响基础SQLite文件中的数据格式。

添加新属性将更改versionHashNSEntityDescription,这就是您遇到此问题的原因。如果您仍在从原始模型中迁移数据,它仍然可以工作。这只是一个问题,因为您拥有的数据使用的模型版本当前与您的应用程序中的任何内容都不匹配。

要修复,请执行以下一项操作:


使用此更改创建新的第三模型版本并迁移到该版本,或者
删除现有数据并再次迁移版本1-> 2,或者
撤消此最新更改,以便您的数据继续与您的最新模型版本匹配。

关于ios - 迁移后在更改核心数据时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29136175/

10-10 21:13
查看更多