简体   繁体   English

迁移后在更改核心数据时崩溃

[英]Crash on change to Core Data after migration

So I am having a weird crash I hope someone can read the crash data. 因此,我发生了一次奇怪的崩溃,希望有人可以读取崩溃数据。 I built a Core Data model about a month ago for an app. 大约一个月前,我为一个应用程序构建了Core Data模型。 It's 12 entities and each entity has several relationships to the other entities. 它是12个实体,每个实体与其他实体都有几种关系。 About two weeks ago (after a Test Flight), I wanted to update the model. 大约两个星期前(试飞之后),我想更新模型。 I versioned the model, add the two flags (NSMigratePersistentStoresAutomaticallyOption, NSInferMappingModelAutomaticallyOption) to the creation of the persistentStoreCoordinator and made my changes. 我对模型进行了版本控制,将两个标志(NSMigratePersistentStoresAutomaticallyOption,NSInferMappingModelAutomaticallyOption)添加到persistentStoreCoordinator的创建中,并进行了更改。 I booted the app, the model was migrated and I was on my way. 我启动了该应用程序,模型已迁移,并且正在路上。 Since then, I have made other changes to Version 2 of the data model without any difficulty. 从那时起,我毫无困难地对数据模型的版本2进行了其他更改。 Today, I added one Boolean Attribute to one entity and now the app crashes at launch. 今天,我向一个实体添加了一个布尔属性,现在该应用在启动时崩溃。 If I delete the newly added attribute, the app works fine. 如果删除新添加的属性,则该应用程序可以正常运行。 I am struggling to understand how over the past two weeks I have added attributes, entities, even relationships to Version 2 without hitch. 我正在努力了解过去两周中我如何轻松地向版本2添加属性,实体甚至关系。 Is this Boolean flag the proverbial straw? 这是布尔标志吗? Any guidance is greatly appreciated. 任何指导,不胜感激。 Here's the crash log: 这是崩溃日志:

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 +

You can't keep changing the same model version and expect Core Data to keep up. 您不能一直更改相同的模型版本并期望Core Data保持更新。 The migration options you're using only apply when the data doesn't match the current model version but does match some older version included in your app. 您使用的迁移选项仅在数据与当前模型版本匹配但与应用程序中包含的某些较旧版本匹配时才适用。 With automatic lightweight migration, Core Data figures out how to update your persistent store to use the new model. 通过自动的轻量级迁移,Core Data可以弄清楚如何更新持久性存储以使用新模型。 If you change the same version of the model, you may prevent Core Data from matching the persistent store file to any model version, and then you get this exception. 如果更改相同版本的模型,则可能会阻止Core Data将持久性存储文件与任何模型版本进行匹配,然后会出现此异常。

You mention that you made some changes and it worked. 您提到您进行了一些更改并且成功了。 Not every change affects the version hash for the model. 并非所有更改都会影响模型的版本哈希。 A Core Data model is uniquely identified by the version hashes of its entities as returned by the [NSEntityDescription versionHash] . 核心数据模型由[NSEntityDescription versionHash]返回的[NSEntityDescription versionHash]的版本哈希唯一标识。 That in turn depends on the result of the value of versionHash on NSRelationshipDescription , NSAttributeDescription , and NSPropertyDescription . 这又取决于价值的结果versionHashNSRelationshipDescriptionNSAttributeDescriptionNSPropertyDescription Some minor changes don't affect any version hashes. 一些较小的更改不会影响任何版本哈希。 In general changes don't affect the version hash unless they affect the formatting of data in the underlying SQLite file. 通常,更改不会影响版本哈希,除非它们影响基础SQLite文件中的数据格式。

Adding a new attribute will change the versionHash of the NSEntityDescription , which is why you're having this problem. 添加新属性将更改versionHashNSEntityDescription ,这就是您遇到此问题的原因。 If you were still migrating data from your original model, it would still work. 如果您仍在从原始模型中迁移数据,它将仍然有效。 It's only a problem because you have data that used a model version that doesn't match anything in your app right now. 这只是一个问题,因为您拥有的数据使用的模型版本当前与您的应用程序中的任何内容均不匹配。

To fix, do one of the following: 要解决此问题,请执行以下一项操作:

  • Create a new third model version with this change and migrate to that, or 使用此更改创建新的第三模型版本并迁移到该版本,或者
  • Remove your existing data and migrate version 1--> 2 again, or 删除现有数据并再次迁移版本1-> 2,或者
  • Undo this most recent change so that your data continues to match your latest model version. 撤消此最新更改,以便您的数据继续与您的最新模型版本匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM