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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:58:41+00:00 2026-05-17T01:58:41+00:00

I’m using Core data in an iOS project. I have the data model setup

  • 0

I’m using Core data in an iOS project. I have the data model setup for automatic data migration whenever I modify entity properties. But I recently made some changes to some entity relationships and now my app crashes with: “Can’t find model for source store”

I realize that resetting the app i.e. deleting and re-installing will solve this issue, bit I have a live version already, and my users will lose all all their data!

So now I’m trying manual migration, but the iOS docs are not very helpful. For instance, I have this code which I run after creating a model mapping:

NSURL *destinationStoreURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"import.sqlite"]];

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"db.sqlite"]]; 

//initialize migration manager
NSMigrationManager *migrationManager = [[NSMigrationManager alloc] initWithSourceModel:[[self persistentStoreCoordinator] managedObjectModel]
                                                                      destinationModel:[[self persistentStoreCoordinator] managedObjectModel]];

//perform migration     
NSError *error = nil;       
NSMappingModel *mappingModel = [NSMappingModel inferredMappingModelForSourceModel:[[self persistentStoreCoordinator] managedObjectModel]
                                                                 destinationModel:[[self persistentStoreCoordinator] managedObjectModel] error:&error];

if (mappingModel == nil) {
    NSLog(@"No Mapping model error %@, %@", error, [error userInfo]);
}

[migrationManager migrateStoreFromURL:sourceStoreURL
                                 type:NSSQLiteStoreType
                              options:nil
                     withMappingModel:mappingModel
                     toDestinationURL:destinationStoreURL
                      destinationType:NSSQLiteStoreType
                   destinationOptions:nil
                                error:&error];  

Running this code works and resets the database, but I cant find my old data, and when I save any new data, I get an error that there is no persistent store!

Does anyone have any ideas?

  • 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-17T01:58:41+00:00Added an answer on May 17, 2026 at 1:58 am

    The guys are right…

    If it’s not too late, try this: Open your “[your database].xcdatamodel” file. Then (assume you are using Xcode), go to your main menu. Select Design > Data Model > Add Model Version. This creates a new file, in our case, “[your database] 2.xcdatamodel”:

    Now go to Design > Data Model > Set Current Version. Doing this tells Xcode that this is the database schema that you’ll be using. Now make whatever database schema changes you want. Now’s probably a good time to make any code changes where your database schema change has been directly effected.

    Now compile your program. This time it should load.

    I encountered the same trouble. This is the first time I’ve actually read the IPhone Development Docs. I had to really pay attention. Now I’m all set. I actually chose lightweight migration. This code was hijacked straight from one (or several) of Apple’s example programs (which often has bugs, just so you’ll know… :-/ )

     - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { 
     if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
     }
    
     NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory]
          stringByAppendingPathComponent:DATABASENAME]];
     NSError *error;
     persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:      
      [self managedObjectModel]];
    
     // Allow inferred migration from the original version of the application.
     NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
            [NSNumber numberWithBool:YES], 
            NSMigratePersistentStoresAutomaticallyOption,
            [NSNumber numberWithBool:YES], 
             NSInferMappingModelAutomaticallyOption, nil];
    
     //ATTENTION: YOU WERE CRASHING HERE...
     if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType 
     configuration:nil URL:storeUrl options:options error:&error]) {
           // Handle the error.
          NSLog(@"WTF??? FAILED to create automatic lightweight migration. Error[%@]", error);
     }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

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.