title: How to write migration to change primary key of model with ManyToManyField
body: <p>I have a <code>UserProfile</code> model that refers to my <code>User</code> model with a <code>OneToOneField</code>.  I also use the <code>post_save</code> signal to auto create the <code>UserProfile</code> when the user is created.  This works great apart from when creating a user through the admin (where I use an inline) when I get an error about duplicate profile.  <a href="https://stackoverflow.com/a/18265192/3189">This answer recommends setting the primary key to be the OneToOneField referring to user</a>.</p>
  
  <p>So before:</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(settings.AUTH_USER_MODEL)
      # ...
      subjects = models.ManyToManyField(Subject, null=True, blank=True)
  </code></pre>
  
  <p>After</p>
  
  <pre><code>class UserProfile(models.Model):
      user = models.OneToOneField(settings.AUTH_USER_MODEL, primary_key=True)
      # ...
      subjects = models.ManyToManyField(Subject, null=True, blank=True)
  </code></pre>
  
  <p>I'm trying to do that using the migrations in Django 1.7, but life is complicated by the fact that the profile has a number of <code>ManyToManyField</code> - so they all refer to the <code>id</code> field of the <code>UserProfile</code> model.  Using <code>makemigrations</code> creates the migrations for making the user the primary key, and dropping the old id field, but it ignores the ManyToManyField.</p>
  
  <p>I'm currently going down a rabbit hole of using lots of <code>RunSQL</code> statements in the migration to modify the through table for the <code>ManyToManyField</code>.  I've just hit another error where the name of the constraint is not the same in one table as another.</p>
  
  <p>So my question is: is there a method in Django migrations that will do the work of changing the through table so it refers to the new primary key, updating all the constraints, keys etc?  If not, what's the best way to handle this situation?</p>
  
  <p>I'm using Django 1.7 with MySQL.</p>