2

So i decided to create 2 sub entities of one of my entity.

To test i created these 2 entities without any attribute neither relationship.

If i use infer mapping model, core data fails and there is a crash in the app. Reported here

If i create a mapping model, core data can't also upgrade. I checked core data log and it says that the entity hashes are correct. What could be wrong here?

 CoreData: annotation: Incompatible version schema for persistent store
 'file://localhost/Users/.../StoreContent/persistentStore'.
 store metadata = {
     NSPersistenceFrameworkVersion = 419;
     NSStoreModelVersionHashes =     {
         Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
         Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
         Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
         User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>;
     };
     NSStoreModelVersionHashesVersion = 3;
     NSStoreModelVersionIdentifiers =     (
         3July13
     );
     NSStoreType = SQLite;
     NSStoreUUID = "73F77A17-9720-4D0E-90DD-D07A0EAECB29";
     "_NSAutoVacuumLevel" = 2; } and current model versions = {
     Broadcast = <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>;
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Group = <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; } 
2013-07-04 10:25:53.678 JonglaIM[90118:22103]
 CoreData: annotation: (migration)   will attempt automatic schema
 migration 2013-07-04 10:25:55.209 x[90118:22103] CoreData:
 annotation: (migration) looking for mapping model with   source
 hashes:  {
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; }  
destination hashes: {
     Broadcast = <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>;
     Chat = <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>;
     Contact = <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>;
     Group = <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>;
     Message = <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d>;
     User = <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>; } 
 2013-07-04 10:25:55.214 x[90118:22103]
 CoreData: annotation: (migration) checking mapping model at path
file://localhost/Users/.../Model.cdm
 source hashes:  {(
     <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>,
     <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>,
     <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>,
     <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d> )}  
destination hashes: {(
     <e2afd25a 758f8e8b 7a2e1f2d 03042e32 e5e23693 a4935257 04a8e9fb 535e2452>,
     <1400bc94 f742db62 91627ea5 883e54a8 104da454 a9a7b073 f1e827ad 26f7e7c8>,
     <7f14d6ac 1bf1035e 63208d38 c048c396 d6385a95 3c8aec0b 36fbb86f 293fdb4d>,
     <67fa7527 b68ea99d ee8e704f 30f20e48 58350963 73e29c19 8aea7604 dfac7d7c>,
     <05d870d5 8d51e966 51a6b121 56fd0eff 6a35760e 829245ce 38e82724 b511b400>,
     <45852277 e01bffe5 a83f71fe 09c20dba 838bb51c 411dc185 56ba4ff1 7b68ba3d> )} 2013-07-04 10:25:55.215 x[90118:22103] CoreData:
 annotation: (migration) no suitable mapping model found
Community
  • 1
  • 1
João Nunes
  • 3,751
  • 31
  • 32
  • Under "looking for mapping model ... destination hashes", the Broadcast line is empty - was that just a bad copy/paste? Assuming it was, have you tried explicitly setting the mapping model to your Model.cdm rather than having CoreData do the comparison to find a match? I suspect that wouldn't solve the issue, but might generate a different error message with more information about why the model isn't accepted (not sure, though, haven't had to explicitly map myself). – David Ravetti Jul 04 '13 at 17:22
  • How do i set the mapping to be my model.cdm file? I just saw that core data searches for my mapping file and it finds it and tries to use, without success. – João Nunes Jul 05 '13 at 09:12
  • I've been looking in my code and bookmarks to figure out how I manually specified the mapping model the one time I tried it, but unfortunately haven't come up with anything. I did run across this, however, which seems identical to your issue and offers a couple of possible solutions: http://blog.vucica.net/2013/04/core-data-migrating-ignores-manual-mapping-model-or-fails-migration-despite-mapping-models-existence.html – David Ravetti Jul 06 '13 at 03:54
  • 1
    See also http://stackoverflow.com/questions/15094213/no-suitable-mapping-model-found-for-core-data-migration?rq=1 I did not find regenerating the mapping model in Xcode 5 to help, but it might work for you. – Steven McGrath Jul 07 '13 at 02:36

2 Answers2

2

It's 2019 now, Xcode v10.2 at the time of writing, and this issue is still relevant.

I added an attribute to my data model (in a new version) and wished to migrate some data to it based on a current attribute to ensure it had a value by the time the store was accessed. I created a new model version, added the attribute, then created the entity mapping file with a custom policy to achieve this.

After banging my head against a wall for an entire day, the instructions here highlighted the fix: https://blog.vucica.net/2013/04/core-data-migrating-ignores-manual-mapping-model-or-fails-migration-despite-mapping-models-existence.html

Basically, in the Xcode Mapping Model editor, swap the "Source" and "Destination" models around, then switch them back again. I verified that this in fact did lead to changes by committing before the change, then observing the slight change to the xcmapping.xml file afterwards.

It's not the first time a silly bug in Xcode has lead to frustration, and it's probably not going to be the last. Oh well. Onwards and upwards!

John Rogers
  • 2,192
  • 19
  • 29
1

The API for specifying a mapping model directly is NSMigrationManager's:

- (BOOL)migrateStoreFromURL:(NSURL *)sourceURL 
    type:(NSString *)sStoreType 
    options:(NSDictionary *)sOptions 
    withMappingModel:(NSMappingModel *)mappings 
    toDestinationURL:(NSURL *)dURL 
    destinationType:(NSString *)dStoreType 
    destinationOptions:(NSDictionary *)dOptions 
    error:(NSError **)error; 

Unfortunately, this isn't likely to help much, as the same hash check is performed when the model is used directly through this API.

The hash logging in iOS 6 is broken, in that it shows matching hashes even when it clearly shouldn't. If you have access to iOS 7 beta, try running there and compare the hashes again. There may also be a little more information in the log to help.

There is a problem with hashes not being correct in some cases, and I am dealing with such an issue myself, but I have been unable to nail down what features in a model may trigger this bug.

If you are able to isolate what triggers this problem, please post back, and file a bug.

Steven McGrath
  • 1,717
  • 11
  • 20