title: Save an object after Delete in Core Data with Restkit make it crash
body: <p>I'm trying to use RestKit and Core Data as a local cache of server side datas, but i can't manage to do it</p>
  
  <p>I created a NSManagedObject :</p>
  
  <pre><code>@interface JSONShop : NSManagedObject
  
  @property (nonatomic, retain) NSNumber * shopId;
  @property (nonatomic, retain) NSNumber * type;
  
  @end
  @implementation JSONShop
  
  @synthesize shopId;
  @synthesize type ;
  
  @end
  </code></pre>
  
  <p>It is automatically mapped and stored by Restkit, and I can fetch it from the database to display it in an TableViewController. </p>
  
  <p>I have a primary key on my table (defined in my mapping), for example :</p>
  
  <pre><code>shopMap.primaryKeyAttribute = @"shopId" ;  
  </code></pre>
  
  <p>When I store my objects for the first time, everything is all right :)</p>
  
  <p>After, when I delete all entities in the context , when Restkit try to map it again and save it again but I obtain this error : </p>
  
  <pre><code>'CoreData could not fulfill a fault for '0x9412ea0 &lt;x-coredata://F8451322-3890-430F-8ABD-B5EEF1DFED2F/JSONShop/p177&gt;'' 
  </code></pre>
  
  <p>Do you know why ?</p>
  
  <p>Here is my delete code :</p>
  
  <pre><code>- (void) deleteAllObjects: (NSString *) entityDescription  {
  
      NSLog(@"Deleting %@",entityDescription);
  
      NSManagedObjectContext * managedObjectContext = [[RKObjectManager sharedManager].objectStore managedObjectContext] ;
      NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:entityDescription inManagedObjectContext:managedObjectContext];
      NSError * error ;
      [fetchRequest setEntity:entity];
  
      NSArray *items = [managedObjectContext executeFetchRequest:fetchRequest error:&amp;error];
  
      for (NSManagedObject *managedObject in items) {
          [managedObjectContext deleteObject:managedObject];
      }
      if (![managedObjectContext save:&amp;error]) {
          NSLog(@"Error deleting %@ - error:%@",entityDescription,error);
      }
  
  }
  </code></pre>