I’m having trouble migrating a store entity attribute from String to Integer 16. Here are the steps I take:
- Add Model Version…
- In the new model, change Entity attribute from String to Int 16.
- Select the new model in File Inspector > Versioned Core Data Model > Current Model
- Create a mapping model for the old and new models.
- Run
Here is the error:
Unresolved error Error Domain=NSCocoaErrorDomain Code=134140 “The
operation couldn’t be completed. (Cocoa error 134140.)”
UserInfo=0xbd5cd20 {reason=Can’t find or automatically infer mapping
model for migration, destinationModel=…
The mapping model is there in the compiled .app:

and in the Project:

Migration works for attributes like Integer 16 > Integer 32, or when changing attribute names.
I tried creating a simple Core Data Project and migration worked automatically (with and without mapping model) from String to Integer 16 and back.
The strangest part is I tried looking programatically for all mapping models in the bundle and none are found for the current source/destination models.
This happens because Core Data is unable to automatically migrate your attribute. This is because it can’t guarantee that a string will always fit in an int (even though you know your data does).
So what you need to do is use a mapping model. Here’s how to do it:
NSEntityMigrationPolicy)createDestinationInstancesForSourceInstance:entityMapping:manager:error:which will give you the source instance so you can convert that string into an int and store it in the new store.Your code should look something like this:
Be sure to change the migration settings to remove automatic type inference wherever you init Core Data
That should be it…