迁移后对Core Data的更改崩溃

时间:2015-03-19 02:25:27

标签: ios core-data

所以我有一个奇怪的崩溃,我希望有人可以读取崩溃数据。我在一个月前为一个应用程序构建了一个Core Data模型。它是12个实体,每个实体与其他实体有几种关系。大约两周前(试飞后),我想更新模型。我对模型进行了版本化,将两个标志(NSMigratePersistentStoresAutomaticallyOption,NSInferMappingModelAutomaticallyOption)添加到persistentStoreCoordinator的创建中并进行了我的更改。我启动了应用程序,模型已迁移,我正在路上。从那时起,我对数据模型的第2版进行了其他更改,没有任何困难。今天,我向一个实体添加了一个布尔属性,现在应用程序在启动时崩溃了。如果我删除新添加的属性,该应用程序工作正常。我很难理解过去两周我是如何在没有障碍的情况下为版本2添加属性,实体甚至关系的。这个布尔标志是众所周知的稻草吗?非常感谢任何指导。这是崩溃日志:

2015-03-18 22:01:16.778 GroupShop[67338:2060644] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///Users/tom/Library/Developer/CoreSimulator/Devices/0FD3C702-3CB8-49AA-AA22-72FED2328608/data/Containers/Data/Application/37785998-3FC9-4C96-ADD4-920BAAB1CCFD/Documents/store.data options:{
    NSInferMappingModelAutomaticallyOption = 1;
    NSMigratePersistentStoresAutomaticallyOption = 1;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x7fb9733d86e0 {URL=file:///Users/tom/Library/Developer/CoreSimulator/Devices/0FD3C702-3CB8-49AA-AA22-72FED2328608/data/Containers/Data/Application/37785998-3FC9-4C96-ADD4-920BAAB1CCFD/Documents/store.data, metadata={
    NSPersistenceFrameworkVersion = 519;
    NSStoreModelVersionHashes =     {
        GSFullImage = <c5bc1212 ba535c9d d2c71ba9 7698bd48 d5389868 79acddbf 227ac7bd 41050fe6>;
        GSGroupShop = <c272e62b 995b4e9f e361e6a1 77357123 2d16180f c14360b6 e5280119 3fbcb50c>;
        GSInvites = <d8858c72 6de5f142 04fbd267 10879385 4cb3ed6c 7d7c0e21 e2eae506 482b74f7>;
        GSItem = <f200451b 61aefbb4 5f0fd9a3 7ce920b6 0da9ce90 871b1178 b818ad43 5548cfe5>;
        GSItemCategory = <9e9259dc f21358fe 5e7666f2 05385024 ce03a9c4 1456b8d0 3cd8ee14 5ada76b8>;
        GSLocation = <77f18fda 31ab27c1 0b678c32 02df009d bd6aa02a 04efae2f b7f95f16 be9c41dd>;
        GSMembers = <59b2dc70 bda93cbd 594ed99e aed5f90e 2dcc17bf 2bd4cdc7 9ee21421 91c975a6>;
        GSMessageText = <eaa0bb73 1c2dbf25 bba2d857 e56c45fa 245fe57e e67970ab 5ba0faba 5662d028>;
        GSNotificationDetail = <f3cd7739 2b3b20c8 1a42784f a91ba748 98b93346 585dcf5e 1b141ec6 6f613676>;
        GSOpinion = <c4567265 e5a04989 c3fd25b5 20603c9f 12a769fc 5a03e791 5f68c11b cd1e1e83>;
        GSPermissions = <efd97c2b 21640078 d3a955bc bf79fa0d b521d884 8d561cc5 ac4a0053 4cd4cad4>;
        GSShoppingItems = <0677f34f 61487e6f 06bdcd5f 3508f95a 0f383320 39dde01f 733afb3a 6cec1343>;
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "B8C295E3-8527-4438-BB39-6CBAFAF97194";
    "_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store} with userInfo dictionary {
    URL = "file:///Users/tom/Library/Developer/CoreSimulator/Devices/0FD3C702-3CB8-49AA-AA22-72FED2328608/data/Containers/Data/Application/37785998-3FC9-4C96-ADD4-920BAAB1CCFD/Documents/store.data";
    metadata =     {
        NSPersistenceFrameworkVersion = 519;
        NSStoreModelVersionHashes =         {
            GSFullImage = <c5bc1212 ba535c9d d2c71ba9 7698bd48 d5389868 79acddbf 227ac7bd 41050fe6>;
            GSGroupShop = <c272e62b 995b4e9f e361e6a1 77357123 2d16180f c14360b6 e5280119 3fbcb50c>;
            GSInvites = <d8858c72 6de5f142 04fbd267 10879385 4cb3ed6c 7d7c0e21 e2eae506 482b74f7>;
            GSItem = <f200451b 61aefbb4 5f0fd9a3 7ce920b6 0da9ce90 871b1178 b818ad43 5548cfe5>;
            GSItemCategory = <9e9259dc f21358fe 5e7666f2 05385024 ce03a9c4 1456b8d0 3cd8ee14 5ada76b8>;
            GSLocation = <77f18fda 31ab27c1 0b678c32 02df009d bd6aa02a 04efae2f b7f95f16 be9c41dd>;
            GSMembers = <59b2dc70 bda93cbd 594ed99e aed5f90e 2dcc17bf 2bd4cdc7 9ee21421 91c975a6>;
            GSMessageText = <eaa0bb73 1c2dbf25 bba2d857 e56c45fa 245fe57e e67970ab 5ba0faba 5662d028>;
            GSNotificationDetail = <f3cd7739 2b3b20c8 1a42784f a91ba748 98b93346 585dcf5e 1b141ec6 6f613676>;
            GSOpinion = <c4567265 e5a04989 c3fd25b5 20603c9f 12a769fc 5a03e791 5f68c11b cd1e1e83>;
            GSPermissions = <efd97c2b 21640078 d3a955bc bf79fa0d b521d884 8d561cc5 ac4a0053 4cd4cad4>;
            GSShoppingItems = <0677f34f 61487e6f 06bdcd5f 3508f95a 0f383320 39dde01f 733afb3a 6cec1343>;
        };
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =         (
            ""
        );
        NSStoreType = SQLite;
        NSStoreUUID = "B8C295E3-8527-4438-BB39-6CBAFAF97194";
        "_NSAutoVacuumLevel" = 2;
    };
    reason = "Can't find model for source store";
}
2015-03-18 22:01:16.781 GroupShop[67338:2060644] CoreData: annotation: NSPersistentStoreCoordinator's current model hashes are {
    GSFullImage = <c5bc1212 ba535c9d d2c71ba9 7698bd48 d5389868 79acddbf 227ac7bd 41050fe6>;
    GSGroupShop = <e46044b3 50e03456 805a1c17 ef91b2f7 11c7c064 12c8ca8a a23388c5 970125c1>;
    GSInvites = <d8858c72 6de5f142 04fbd267 10879385 4cb3ed6c 7d7c0e21 e2eae506 482b74f7>;
    GSItem = <f200451b 61aefbb4 5f0fd9a3 7ce920b6 0da9ce90 871b1178 b818ad43 5548cfe5>;
    GSItemCategory = <9e9259dc f21358fe 5e7666f2 05385024 ce03a9c4 1456b8d0 3cd8ee14 5ada76b8>;
    GSLocation = <77f18fda 31ab27c1 0b678c32 02df009d bd6aa02a 04efae2f b7f95f16 be9c41dd>;
    GSMembers = <59b2dc70 bda93cbd 594ed99e aed5f90e 2dcc17bf 2bd4cdc7 9ee21421 91c975a6>;
    GSMessageText = <eaa0bb73 1c2dbf25 bba2d857 e56c45fa 245fe57e e67970ab 5ba0faba 5662d028>;
    GSNotificationDetail = <f3cd7739 2b3b20c8 1a42784f a91ba748 98b93346 585dcf5e 1b141ec6 6f613676>;
    GSOpinion = <c4567265 e5a04989 c3fd25b5 20603c9f 12a769fc 5a03e791 5f68c11b cd1e1e83>;
    GSPermissions = <efd97c2b 21640078 d3a955bc bf79fa0d b521d884 8d561cc5 ac4a0053 4cd4cad4>;
    GSShoppingItems = <0677f34f 61487e6f 06bdcd5f 3508f95a 0f383320 39dde01f 733afb3a 6cec1343>;
}
2015-03-18 22:01:16.831 GroupShop[67338:2060644] *** Terminating app due to uncaught exception 'Open Failure', reason: 'Reason: The operation couldn’t be completed. (Cocoa error 134130.)'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ce84a75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010bfe2bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010ce849ad +[NSException raise:format:] + 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 application: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 main + 

1 个答案:

答案 0 :(得分:1)

您无法继续更改相同的型号版本,并期望Core Data能够跟上。您使用的迁移选项仅适用于数据与当前模型版本不匹配但 匹配您应用中包含的旧版本的情况。通过自动轻量级迁移,Core Data可以了解如何更新持久性存储以使用新模型。如果更改模型的相同版本,则可能会阻止Core Data将持久性存储文件与任何模型版本匹配,然后您将获得此异常。

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

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

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

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