title: iPhone Core Data "Automatic Lightweight Migration"
body: <p>I am attempting to update an app that implements a core data store.  I am adding an attribute to one of the entities. </p>
  
  <p>I added the following code to my delegate class:</p>
  
  <pre><code>- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  
      if (persistentStoreCoordinator != nil) {
          return persistentStoreCoordinator;
      }
  
      NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Shoppee.sqlite"]];
  
      NSError *error = nil;
      persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
  
      NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                               [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
  
      if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&amp;error]) {
          NSLog(@"Error: %@",error);
          NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
          abort();
      }    
  
      return persistentStoreCoordinator;
  }
  </code></pre>
  
  <p>This was from the following URL:
  <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweight.html#//apple_ref/doc/uid/TP40008426-SW1" rel="noreferrer">Doc</a></p>
  
  <p>I get the following error when executing the code:</p>
  
  <blockquote>
    <p>2009-12-01 20:04:22.877</p>
    
    <p>Shoppee[25633:207] Error: Error</p>
    
    <p>Domain=NSCocoaErrorDomain Code=134130</p>
    
    <p>UserInfo=0x1624d20 "Operation could not be completed. (Cocoa error
    134130.)" 2009-12-01 20:04:22.879 Shoppee[25633:207] Unresolved error
    Error Domain=NSCocoaErrorDomain Code=134130 UserInfo=0x1624d20
    "Operation could not be completed. (Cocoa error 134130.)", {
        URL = file://localhost/Users/Eric/Library/Application%20Support/iPhone%20Simulator/User/Applications/A8A8FB73-9AB9-4EB7-8F83-82F5B4467AF1/Documents/MyApp.sqlite;
        metadata =     {
            NSPersistenceFrameworkVersion = 241;
            NSStoreModelVersionHashes =         {
                Item = &lt;869d4b20 088e5c44 5c345006 87d245cd 67ab9bc4 14cadf45
    180251e9 f741a98f>;
                Store = &lt;47c250f4 895e6fd1 5033ab42 22d2d493 7819ba75 3c0acffc
    2dc54515 8deeed7a>;
            };
            NSStoreModelVersionHashesVersion = 3;
            NSStoreModelVersionIdentifiers =         (
            );
            NSStoreType = SQLite;
            NSStoreUUID = "8DC65301-3BC5-42BE-80B8-E44577B8F8E1";
        };
        reason = "Can't find model for source store"; }</p>
  </blockquote>
  
  <p>It looks like I somehow need to include the original data model but I am not sure how to do that.  Any suggestions?</p>