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 3356562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:31:40+00:00 2026-05-18T02:31:40+00:00

Everytime I add a new Attribute to my CodeData object model I have to

  • 0

Everytime I add a new Attribute to my CodeData object model I have to clear my database file out otherwise I get the following error:

2010-11-13 15:26:44.580 MyApp[67066:207] * Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘+entityForName: could not locate an NSManagedObjectModel for entity name ‘myApp”

There must be a way of being able to add extra fields without losing the whole database.

What do I need to do to retain my data?

  • 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-05-18T02:31:41+00:00Added an answer on May 18, 2026 at 2:31 am

    there is a way, and this way is called automatic lightweight migration. It needs a codechange and an extra step when changing your object model.

    For the code you have to add two options to the method where you initialize your persistent store coordinator. something like this:

    - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
        if (persistentStoreCoordinator_ != nil) {
            return persistentStoreCoordinator_;
        }
        NSString *storePath = [AppDelegate_Shared coredataDatabasePath];
        NSURL *storeURL = [NSURL fileURLWithPath:storePath];
    
    // important part starts here
        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, 
                                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
                                 nil];
        NSError *error = nil;
        persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
        if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
    // and ends here
    
            LogError(@"Unresolved error %@, %@", error, [error userInfo]);
            // Do something 
        }    
        return persistentStoreCoordinator_;
    }
    

    Now if you want to change your model, you have to create a model version before you do any changes.
    Select your datamodel, and go into the main menu Design -> Data Model -> Add Model Version. Your “old” model will be renamed and you make your changes in the current model, the one with the green mark.
    All the old models are kept and will be put into your application, so your app can perform the ‘automatic lightweight migration’ and upgrade the existing database to your new model.

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

Sidebar

Related Questions

Why is it everytime i tried to add a new attribute to a node,
I have this div i which I add more divs with javascript. However, everytime
I'm relatively new to Android but I just cant google this. I have following
In my code, every time I need a new object attribute for my class,
I have created an ad-hoc provision profile for my iPhone application. Everytime I add
Everytime I add a new Form to my WinForms project, the designer generates code
It's a weird problem but every time I add a new document to Lucene.net
I am trying to add a new column into an SQLiteDatabase but every time
Everytime I add/create or copy a Project inside my Eclipse-Workspace it will be recognized
I have added custom attribute with the code my_price with Catalog Input Type for

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.