Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8009079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:20:32+00:00 2026-06-04T18:20:32+00:00

I’m having trouble migrating a store entity attribute from String to Integer 16. Here

  • 0

I’m having trouble migrating a store entity attribute from String to Integer 16. Here are the steps I take:

  1. Add Model Version…
  2. In the new model, change Entity attribute from String to Int 16.
  3. Select the new model in File Inspector > Versioned Core Data Model > Current Model
  4. Create a mapping model for the old and new models.
  5. 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:

Bundle

and in the Project:

enter image description here

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:20:33+00:00Added an answer on June 4, 2026 at 6:20 pm

    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:

    1. In Xcode, create a new mapping model (File > New > New File), select Mapping Model in the Core Data section
    2. Select the source and target models in the wizard
    3. This basically puts you in the same place as the lightweight migration, everything is done automatically, except you have the option to override some mapping. Specifically, that one that is giving you troubles.
    4. Create a new mapping policy class (Extend NSEntityMigrationPolicy)
    5. Implement 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:

    - (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
    {
        NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager destinationContext]];  
    
        // Copy all the values from sInstance into newObject, making sure to apply the conversion for the string to int when appropriate. So you should have one of these for each attribute:
        [newObject setValue:[sInstance valueForKey:@"xyz"] forKey:@"xyz"];
    
        [manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping];
    }
    
    1. Then all you have to do is set that policy in the mapping model. Select the mapping model file, pick the appropriate Entity mapping and set the CustomPolicy on the right panel.

    Be sure to change the migration settings to remove automatic type inference wherever you init Core Data

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, nil];
    

    That should be it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.