Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your persistentStoreCoordinator method give this line of code</p> <pre><code> NSDictionary *options=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,[NSNumber numberWithBool:YES],NSInferMappingModelAutomaticallyOption, nil]; </code></pre> <p>If this doesnt help then you need to go for user implemented migration. So you will have to create a mapping model using source and destination model. In that case set,</p> <pre><code>NSDictionary *options=[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],NSMigratePersistentStoresAutomaticallyOption,[NSNumber numberWithBool:NO],NSInferMappingModelAutomaticallyOption, nil]; </code></pre> <p>Create douce metadata with following code</p> <pre><code>if (sourceMetadata) { NSString *configuration = nil; NSManagedObjectModel *destinationModel = [self.persistentStoreCoordinator managedObjectModel]; //Our Source 1 is going to be incompatible with the Version 2 Model, our Source 2 won't be... BOOL pscCompatible = [destinationModel isConfiguration:configuration compatibleWithStoreMetadata:sourceMetadata]; NSLog(@"Is the STORE data COMPATIBLE? %@", (pscCompatible==YES) ?@"YES" :@"NO"); if (pscCompatible == NO) { migrationSuccess = [self performMigrationWithSourceMetadata:sourceMetadata toDestinationModel:destinationModel]; } } else { NSLog(@"checkForMigration FAIL - No Source Metadata! \nERROR: %@", [error localizedDescription]); } </code></pre> <p>and implement the following function</p> <pre><code>- (BOOL)performMigrationWithSourceMetadata :(NSDictionary *)sourceMetadata toDestinationModel:(NSManagedObjectModel *)destinationModel { BOOL migrationSuccess = NO; //Initialise a Migration Manager... NSManagedObjectModel *sourceModel = [NSManagedObjectModel mergedModelFromBundles:nil forStoreMetadata:sourceMetadata]; //Perform the migration... if (sourceModel) { NSMigrationManager *standardMigrationManager = [[NSMigrationManager alloc] initWithSourceModel:sourceModel destinationModel:destinationModel]; //Retrieve the appropriate mapping model... NSMappingModel *mappingModel = [NSMappingModel mappingModelFromBundles:nil forSourceModel:sourceModel destinationModel:destinationModel]; if (mappingModel) { NSError *error = nil; NSString *storeSourcePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Recipes.sqlite"]; NSURL *storeSourceUrl = [NSURL fileURLWithPath: storeSourcePath]; NSString *storeDestPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"Recipes2.sqlite"]; NSURL *storeDestUrl = [NSURL fileURLWithPath:storeDestPath]; //Pass nil here because we don't want to use any of these options: //NSIgnorePersistentStoreVersioningOption, NSMigratePersistentStoresAutomaticallyOption, or NSInferMappingModelAutomaticallyOption NSDictionary *sourceStoreOptions = nil; NSDictionary *destinationStoreOptions = nil; migrationSuccess = [standardMigrationManager migrateStoreFromURL:storeSourceUrl type:NSSQLiteStoreType options:sourceStoreOptions withMappingModel:mappingModel toDestinationURL:storeDestUrl destinationType:NSSQLiteStoreType destinationOptions:destinationStoreOptions error:&amp;error]; NSLog(@"MIGRATION SUCCESSFUL? %@", (migrationSuccess==YES)?@"YES":@"NO"); } } else { //TODO: Error to user... NSLog(@"checkForMigration FAIL - No Mapping Model found!"); abort(); } return migrationSuccess; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload