title: deleting core data persistent store instead of migrating (also using RestKit)
body: <p>I'm making quite a few changes to the object model for our app upgrade release ie. entities added / removed, new attributes and relationships.  It seems like the work would really add up for a proper core data migration.  Since the data primarily serves as a cache to enhance the offline browsing experience. at this point doesnt really <em>need</em> migration I would think it would be a whole lot simpler if it were just blown away and recreated.</p>
  
  <p>Based on various posts I've come across on this topic the general strategy is to</p>
  
  <ul>
  <li>detect that the model has changed (by catching the exception during
  initialization of the managedObjectContext)</li>
  <li>delete the persistent store (in our case on iOS the sqlite file)</li>
  <li>reinitialize an objectModel with the latest schema reinitialize a persistent store
  with the new model</li>
  </ul>
  
  <p>This is the code that reinitializes the objectModel</p>
  
  <pre><code>- (NSManagedObjectModel *)managedObjectModel {
  
  if (managedObjectModel != nil) {
      return managedObjectModel;
  }
  
  NSString *path = [[NSBundle mainBundle] pathForResource:@"&lt;model name&gt;" ofType:@"momd"];
  NSURL *momURL = [NSURL fileURLWithPath:path];
  managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];
  
  return managedObjectModel; 
  }
  </code></pre>
  
  <p>and recreating the objectModel and store with </p>
  
  <pre><code>objectManager = [RKObjectManager objectManagerWithBaseURL:
                       [NSString stringWithFormat:@"http://%@/v3", 
                        [[NSBundle mainBundle] objectForInfoDictionaryKey:@"APIDomain"]]];     
  NSManagedObjectModel *objectModel = [self managedObjectModel];
  objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:storeName usingSeedDatabaseName:nil managedObjectModel:objectModel delegate:nil]; 
  </code></pre>
  
  <p>However, I get the following error: </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'UTCity''</p>
  </blockquote>
  
  <p>I feel like it's pretty close since restarting the app succeeds in creating a new store runs correctly.</p>
  
  <p>-PF</p>