title: Yet another, reason: '+entityForName: could not locate an NSManagedObjectModel for entity name
body: <p>I've got the following error:</p>
  
  <pre><code>2012-04-18 10:15:49.585 FoodXJournal[13931:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'CommodityTypes''
  </code></pre>
  
  <p>I've read most of the other questions with this subject, and done some checking.</p>
  
  <p>I have a detail view controller containing a static table view. One cell of the table view is labeled "Delete" and is linked to a segue named "deleteCT". I want the the app to delete <code>self.detailItem</code> and segue to the master view controller when this cell is tapped. Here's my method. All of the NSLog lines are for debugging this.</p>
  
  <pre><code>- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
      if ([[segue identifier] isEqualToString:@"deleteCT"]) {
          if (![self.detailItem.myCommodities count]) {
              NSLog(@"Testing");
              NSLog(@"myCommodities is empty:%@", [self.detailItem.myCommodities count]);
              NSLog(@"self.detailItem HAS a context:%@", [self.detailItem managedObjectContext]);
              NSLog(@"self.detailItem is of CommodityTypes:%@", [[self.detailItem entity] name]);
              NSLog(@"self.detailItem has a managed object model:%@", [[self.detailItem entity] managedObjectModel]);
              [[self.detailItem managedObjectContext] deleteObject:self.detailItem];
          }
      }
  }
  </code></pre>
  
  <p>Here's the log. I do get in to this method,</p>
  
  <pre><code>2012-04-18 10:15:49.544 FoodXJournal[13931:fb03] Testing
  </code></pre>
  
  <p>I meet my condition for deleting,</p>
  
  <pre><code>2012-04-18 10:15:49.544 FoodXJournal[13931:fb03] myCommodities is empty:(null)
  </code></pre>
  
  <p>The error message says <code>'+entityForName: could not locate an NSManagedObjectModel for entity name 'CommodityTypes'</code>, but <code>self.detailItem</code> HAS a context.</p>
  
  <pre><code>2012-04-18 10:15:49.545 FoodXJournal[13931:fb03] self.detailItem HAS a context:&lt;NSManagedObjectContext: 0x6d7e740&gt;
  </code></pre>
  
  <p>Yes, <code>self.detailItem</code> is the entity type I'm thinking of:</p>
  
  <pre><code>2012-04-18 10:15:49.546 FoodXJournal[13931:fb03] self.detailItem is of CommodityTypes:CommodityTypes
  </code></pre>
  
  <p>And, yes, that entity type (<code>NSLog(@"self.detailItem is of CommodityTypes:%@", [[self.detailItem entity] name]);</code>) has a managed object model:</p>
  
  <p>The managed object model description is quite long, so I'm only showing the first part of it here:</p>
  
  <pre><code>2012-04-18 10:15:49.565 FoodXJournal[13931:fb03] self.detailItem has a managed object model:(&lt;NSManagedObjectModel: 0x6d73250&gt;) isEditable 0, entities {
  Accounts = "(&lt;NSEntityDescription: 0x6d71120&gt;) name Accounts, managedObjectClassName Accounts, renamingIdentifier Accounts, isAbstract 0, superentity name Grandparent, properties {\n    \"account_1\" = \"(&lt;NSAttributeDescription: 0x6d6e9d0&gt;), name account_1, isOptional 1, isTransient 0, entity Accounts,
  </code></pre>
  
  <p>scrolling down:</p>
  
  <pre><code>CommodityTypes = "(&lt;NSEntityDescription: 0x6d71240&gt;) name CommodityTypes, managedObjectClassName CommodityTypes, renamingIdentifier CommodityTypes, isAbstract 0, superentity name Grandparent, properties {\n    myCommodities = \"(&lt;NSRelationshipDescription: 0x6d701f0&gt;), name myCommodities, isOptional 1, isTransient 0, entity CommodityTypes, 
  </code></pre>
  
  <p><code>CommodityTypes</code> is defined in the managed object model.</p>
  
  <p>So why does <code>[[self.detailItem managedObjectContext] deleteObject:self.detailItem];</code> crash?!?</p>
  
  <p>Is there some reason I can't delete <code>self.detailItem</code> within prepareForSegue? Do I need to assign an action to the cell or label and then programatically call the segue?</p>