title: NSInternalInconsistencyException while adding Core Data into an application
body: <p>I am adding Core Data into an existing application, I am following these steps:</p>
  
  <ul>
  <li><p>Importing the framework </p></li>
  <li><p>Creating the model</p></li>
  </ul>
  
  <p>In addition to set up the stack, I'm using the following code:</p>
  
  <pre><code>- (NSManagedObjectContext *) managedObjectContext {
      if (managedObjectContext != nil) {
          return managedObjectContext;
      }
      NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
      if (coordinator != nil) {
          managedObjectContext = [[NSManagedObjectContext alloc] init];
          [managedObjectContext setPersistentStoreCoordinator: coordinator];
      }
  
      return managedObjectContext;
  }
  
  - (NSManagedObjectModel *)managedObjectModel {
      if (managedObjectModel != nil) {
          return managedObjectModel;
      }
      managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
  
      return managedObjectModel;
  }
  
  -(NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  
      if (persistentStoreCoordinator != nil) {
          return persistentStoreCoordinator;
      }
  
      NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"xxxxx.sqlite"]];
  
      NSError *error = nil;
      persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
      if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&amp;error]) {
         // Handle error
      }    
  
      return persistentStoreCoordinator;
  }
  
  - (NSString *)applicationDocumentsDirectory {
      return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  }
  </code></pre>
  
  <p>But when I am trying to save data I get the following execption</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    <code>NSInternalInconsistencyException</code>, reason: 'This
    <code>NSPersistentStoreCoordinator</code> has no persistent stores.  It cannot
    perform a save operation.'</p>
  </blockquote>