Magic record migration error "Cannot find model for source store"

We made some changes to our CoreData model and look like an automatic migration error.

Even when we set the current model as the original model that we used to generate the data, there is still an error:

reason = "Unable to find model for source store";

2014-09-05 02:19:43.297[948:166846] -[LBAppDelegate application:willFinishLaunchingWithOptions:] line 132 $ WILL FINISH!! 2014-09-05 02:19:43.402[948:166846] +[LBParse ensureUserObjectExists] line 107 $ dont save 2014-09-05 02:19:52.395[948:166846] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat... options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; NSSQLitePragmasOption = { "journal_mode" = WAL; }; } ... returned error Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn't be completed. (Cocoa error 134130.)" UserInfo=0x180f8620 {URL=file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat..., metadata={ NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>; AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>; Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>; Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>; Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>; AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>; Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>; Data = <92870bec c4a8794e 293dcbe9 93282d69 cb675039 cb9b9bf6 8dda6359 34697663>; Event = <de060947 8ec9f2bb 80e341eb 787e7eec 7cc2a09f 356e511c 7d515ca5 130690fe>; FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>; Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>; Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>; ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>; Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>; User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>; Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "222748EF-2F19-4B87-829C-F8171E439430"; "_NSAutoVacuumLevel" = 2; }, reason=Can't find model for source store} with userInfo dictionary { URL = "file:///var/mobile/Containers/Data/Application/0B3D4097-940C-433F-B6E5-E0EA6B08992F/Library/Applicat..."; metadata = { NSPersistenceFrameworkVersion = 519; NSStoreModelVersionHashes = { AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>; AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>; Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>; Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>; Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>; AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>; Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>; Data = <92870bec c4a8794e 293dcbe9 93282d69 cb675039 cb9b9bf6 8dda6359 34697663>; Event = <de060947 8ec9f2bb 80e341eb 787e7eec 7cc2a09f 356e511c 7d515ca5 130690fe>; FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>; Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>; Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>; ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>; Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>; User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>; Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>; }; NSStoreModelVersionHashesVersion = 3; NSStoreModelVersionIdentifiers = ( "" ); NSStoreType = SQLite; NSStoreUUID = "222748EF-2F19-4B87-829C-F8171E439430"; "_NSAutoVacuumLevel" = 2; }; reason = "Can't find model for source store"; } 2014-09-05 02:19:52.404 [948:166846] CoreData: annotation: NSPersistentStoreCoordinator current model hashes are { AccessItem = <c81a9dbd 17033d2e 91d33b1c fc94ab08 bd3619e2 b5fea24d 6881959a f8023dc5>; AccessRule = <e0fd9950 87366a29 fa6702bf 7e7acc3a 86c2f088 3875c341 81414177 4720eee8>; Airline = <f8491ecb 2628a003 143b935b 3d3c291b fac507d8 2339af1b 1ac0fe8b 04b73602>; Airport = <09e93c0e fbf1e542 d1428584 30549a84 2e0cb9d3 8b50a508 31807dec d7e5f845>; Alliance = <b9b53f23 d5962f3f b7a0a3a5 5ca84d83 61d81f7c 0787ca6a dfdfdf21 733b5e4d>; AllianceTier = <6ec8bee0 5d4c62f8 1411eaab b464d783 c6388b12 06506824 f11d6453 a58e509a>; Amenity = <86065297 64aff55b b7bfec32 e8e14b74 5d7afa5b 751e760e e37e6294 2e40e26a>; FeedItem = <1d0d12fc 82eb532a c1a42ad3 57022129 2c44360e ab5514ce a44d6de0 719ca798>; Image = <94e1ad81 4a2aa37b 6a02a52e fb481891 5028fafc 0645de55 7316e5d9 f630ca85>; Lounge = <57e5d036 c67f1f9d b3c731a6 4136866e 008684b0 f2ec0620 58e6e56c dbbed4fe>; ParseObject = <bfa49e8c 1108961a 49848584 0f2fe83f 082bdc6a 2948e09f 68a84c50 2acb0699>; Review = <b423b85c 47d15ee8 bbacbfcf 019fb741 165da2ab 5fa6f087 1975bb31 712bdb64>; User = <8451767f db80e10a 15ea83d8 83dc1a2c e89d1699 0b302640 59a23144 61c65be0>; Vote = <38d267c9 0c44854e dd01201c b728b906 21fd25cd 8343a416 adf769c6 faef7cb6>; } 
+5
source share
2 answers

You have a model, but it is not compatible with the store. It seems to me that you made changes to the model without adding a version. For any migration of master data, you need a source model and a target model. That is, the master data needs to know how the source data looks and how the new data looks. Then Core Data can push (pull) changes between models for automatic migration. Since the original model was not found in this case, and I assume that you still have a model that is in your project, you probably changed the data model without adding a version. We hope you use some control source and can return to the version of the data model that corresponds to the store. From there you need to " Add Model Version ". Look for it in one of the Xcode menus. You will also need to make sure that the new version is the current version of the model for the transition to work properly.

And if you use MagicalRecord, you can use one of the simple helper methods that transfer data when the store is attached.

+9
source

This can also happen if your previous version has not changed, but you have several xcdatamodel files and load them using mergedModelFromBundles: This is how MagicalRecord loads your model files.

So, if you have a dependency (possibly on your containers) that has a different xcdatamodel, then your actual source data model will not be the same as the one you are transitioning with, since the source data model is a unified model of everything from for mergedModelFromBundles:

To solve this problem, you will need to create a simple version that matches what is stored, and not just in the previous version. To do this, add the missing models to the source data model you are switching from, and you will get these models from another xcdatamodel . Fortunately, you can simply copy and paste all models by selecting them from the list of objects.

For instance:

To: (Fails)

 Main.xcdatamodel Version 2: Users, Posts, Comments Version 1: Users, Posts Other.xcdatamodel Version 1: Events, Data 

After:

 Main.xcdatamodel Version 2: Users, Posts, Comments Version 1: Users, Posts, Events, Data Other.xcdatamodel Version 1: Events, Data 

Saved Data Model:

 Version 1: Users, Posts, Events, Data Version 2: Users, Posts, Comments, Events, Data 
+5
source

Source: https://habr.com/ru/post/1201886/


All Articles