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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:38+00:00 2026-05-27T14:28:38+00:00

I just created a new version of my core data model with an extra

  • 0

I just created a new version of my core data model with an extra object along with reworked relationships.

I now now have both files, Medical_Codes.xcdatamodel and Medical_Codes_ 2.xcdatamodel.

Do I have to delete the old NSManagedObject class files and recreate them?

Do I have to change my persistent store code?

- (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil)
    {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Medical_Codes" withExtension:@"mom"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return __managedObjectModel;
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Medical_Codes.sqlite"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath:[storeURL path]])
    {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"Medical_Codes" ofType:@"sqlite"];

        if (!defaultStorePath)
        {
            NSLog(@"Error: Could not locate Medical_Codes.sqlite in app bundle");
            return nil;
        }

        NSError *error = nil;

        if (![fileManager copyItemAtPath:defaultStorePath toPath:[storeURL path] error:&error])
        {
            NSLog(@"Error copying sqlite from bundle to documents directory: %@, %@", error, [error userInfo]);
            return nil;
        }
    }

    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    

    return __persistentStoreCoordinator;
}
  • 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-27T14:28:38+00:00Added an answer on May 27, 2026 at 2:28 pm

    CoreData provides various levels of migration of a database’s old schema to the new schema. Sometimes you can do a lightweight migration, which means you don’t have to do anything special except create your new model and generate the new managed object classes. The next time you fire up your application, the model manager does its magic and migrates your old data to the new schema.

    However, when your new model is significantly different from the old model, then you are required to create a model mapping file that gives CoreData the necessary migration information to map from old to new. This mapping model file is copied into your bundle by Xcode and the model manager uses it to make the necessary migration.

    You will also need to pass some additional options during the creation persistent store coordinator at runtime (So, yes, you have to change your persistent store coordinator code a tiny bit). Somewhat like:

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
        [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
        [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, 
        nil];
    
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
        ...
    }
    

    So, to answer your first question. If you added new attributes or relations, then you will need to create new managed object file(s). If all you did was modify some of the options on pre-existing attributes or relations, then your old managed object file(s) are still valid.

    If you haven’t yet, you should read everything Apple has written about CoreData. I have yet to read a book on the subject that covers it any better than their online documentation. In particular, read their information on versioning and migration.

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

Sidebar

Related Questions

I just created a new table and filled it with data. When I run
I've just created a new view based application, and now I want to set
I've released an app with a Core Data sqlite database. In the new version
I have created a new application in my dev environment, and now need to
I have some basic questions about core data (which I am new to) and
I've just created a new Windows XP VM on my Mac using VMware Fusion.
I'm new to silverlight and wpf programming I've just created a simple storyboard in
I just installed ruby on rails on windows. install mysql and created a new
I've just create a new MVC project, and have made no changes at all,
I just created a new Xcode project. In the AppControl class Header file I

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.