title: Primary Key Issues with ManyToManyField Relationships in Django
body: <p>I am attempting to use ManyToMany relationships in Django and almost everything is working perfectly.  I have <strong>resources</strong> and <strong>case studies</strong>.  The objective is to have (case studies) able to pull any number of items from the resources table.</p>
  
  <p>Here is what works perfectly</p>
  
  <ul>
  <li>I can add resources</li>
  <li>I can edit resources</li>
  <li>I can add case studies</li>
  <li>I can edit case studies</li>
  </ul>
  
  <p>I cannot</p>
  
  <ul>
  <li>I cannot delete resources</li>
  <li>I cannot delete case studies</li>
  </ul>
  
  <p>I have one relational table to handle this relationship:</p>
  
  <p><strong>casestudy_resource</strong> (table)</p>
  
  <pre>
     casestudy_id      resource_id
     1                 2
     1                 5
     1                 9
  </pre>
  
  <p><strong>Models.py</strong></p>
  
  <pre><code>class Resource(models.Model):
      title = models.CharField(max_length=200, null=False, blank=False)
      date = models.DateTimeField(null=False, blank=False)
      intro = models.CharField(max_length=1000, default=None, null=False, blank=True)
      file = models.FileField(upload_to=pdf_location, null=True, blank=True)
  
      def __unicode__(self):
          return self.title
  
  class Casestudy(models.Model):
      title = models.CharField(max_length=400, null=False, blank=False)
      meta_keywords = models.CharField(max_length=500, null=True, blank=True)
      meta_description = models.CharField(max_length=500, null=True, blank=True)
      thumbnail = models.ImageField(upload_to=image_location, null=True, blank=True, help_text="120w x 100h")
      file = models.FileField(upload_to=pdf_location, null=True, blank=True)
      resource = models.ManyToManyField(Resource, blank=True, null=True)
  
      class Meta:
          verbose_name = "Case Study"
          verbose_name_plural = "Case Studies"
  
      def __unicode__(self):
          return self.title 
  </code></pre>
  
  <p><strong>PRIMARY KEY ISSUE</strong></p>
  
  <p>I receive the following database exception when performing a delete from the above code:</p>
  
  <pre><code>no such column: casestudy_resource.id
  </code></pre>
  
  <hr>
  
  <p><strong>SECONDARY ISSUE</strong></p>
  
  <p>When adding a primary key to fix the above column, only null values appear in the primary key column.  They are oddly not auto-generated like all other primary keys in Django models:</p>
  
  <p><strong>casestudy_resource</strong> (table)</p>
  
  <pre>
      id        casestudy_id      resource_id
      NULL      1                 2
      NULL      1                 5
      NULL      1                 9
  </pre>
  
  <p>This then causes the following exception when dealing with deleting of resources or case studies:</p>
  
  <pre><code>'NoneType' object has no attribute 'resource'
  </code></pre>