title: How to remove a core data persistent store
body: <p>I need to delete my persistent store (doing it object by object is not practical because I have over 100,000 objects). I've tried this:</p>
  
  <pre><code>- (IBAction)resetDatabase:(id)sender {
  
      NSPersistentStore* store = [[__persistentStoreCoordinator persistentStores] lastObject];
  
      NSError *error = nil;
      NSURL *storeURL = store.URL;
  
      // release context and model
      [__managedObjectContext release];
      [__managedObjectModel release];
      __managedObjectModel = nil;
      __managedObjectContext = nil;
  
      [__persistentStoreCoordinator removePersistentStore:store error:nil];
  
      [__persistentStoreCoordinator release];
      __persistentStoreCoordinator = nil;
  
      [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&amp;error];
      if (error) {
          NSLog(@"filemanager error %@", error);
      }    
  
       // recreate the stack
       __managedObjectContext = [self managedObjectContext];
  
  }
  </code></pre>
  
  <p>But I get this error when I try to insert entities into the store afterwards:</p>
  
  <pre><code>This NSPersistentStoreCoordinator has no persistent stores.  It cannot perform a save operation.
  </code></pre>
  
  <p><strong>Update:</strong>
  I tried releasing the MOC and MOM before removing the persistent store but I still get the same error.</p>