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

  • Home
  • SEARCH
  • 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 1054059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:20:47+00:00 2026-05-16T17:20:47+00:00

I wish to migrate from my version1 data model to version2, but once the

  • 0

I wish to migrate from my version1 data model to version2, but once the migration is complete I wish to perform some custom migration code. How will I know if/when the migration occurs? Is there a migrationHasCompleed delegate method or notification?

For interests sake: The custom migration code I wish to perform resizes png’s in the database.

  • 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-16T17:20:48+00:00Added an answer on May 16, 2026 at 5:20 pm

    Well, you could run this code right after the migration happen, on your persistent store coordinator setup:

    + (NSPersistentStoreCoordinator *)persistentStoreCoordinatorForStore:(NSString *)store {
        NSURL *storeUrl = [NSURL fileURLWithPath:[[[self class] applicationDocumentsDirectory] stringByAppendingPathComponent:store]];
    
        NSError *error = nil;
        NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[[self class] managedObjectModel]];
    
        // Check for model changes without trying to update
        if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
            // Set the automatic update options for the current model
            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]) {
    
                NSLog(@"Error opening the database. Deleting the file and trying again.");
    
                //delete the sqlite file and try again
                [[NSFileManager defaultManager] removeItemAtPath:storeUrl.path error:nil];
                if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error])
                {
                    /*
                     Replace this implementation with code to handle the error appropriately.
    
                     abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
    
                     Typical reasons for an error here include:
                     * The persistent store is not accessible
                     * The schema for the persistent store is incompatible with current managed object model
                     Check the error message to determine what the actual problem was.
                     */
                    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
                    abort();
                }
            } else { // The model was updates successfuly
                // Implement here your custom migration code
            }
    
        }    
    
        return [persistentStoreCoordinator autorelease];
    }
    

    Cheers,

    vfn

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

Sidebar

Related Questions

I wish to migrate some data from a single table into these new THREE
i'm trying to migrate some data from two tables in an OLD database, to
i wish to send some data as array from my iphone app to server
I wish to migrate the database of a legacy web app from SQL Server
I wish to set some properties in MyFilter with constructor injection but it seems
I wish to set items from a list to the selectonemenu in icefaces. But
I wish to test a function that will generate lorem ipsum text, but it
I wish to perform an experiment many different times. After every trial, I am
We are about to migrate an intranet web application from using a proprietary forms-based
I wish to, using JQuery, show and hide some anchor tags as I hover

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.