How to write migration to change primary key of model with ManyToManyField
问题 I have a UserProfile model that refers to my User model with a OneToOneField . I also use the post_save signal to auto create the UserProfile 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. This answer recommends setting the primary key to be the OneToOneField referring to user. So before: class UserProfile(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL) # ...