Seems like this should be "easy" or at least documented somewhere, I just cant find it.
Lets say I have a model:
class A(models.Model):
users = models.ManyToMany('auth.User', blank=True)
Now I want to migrate to have a through
table to add fields to the ManyToMany relation...
class AUsers(models.Model):
user = models.ForeignKey('auth.User')
a = models.ForeignKey('A')
new_field = models.BooleanField()
class A(models.Model):
users = models.ManyToMany('auth.User', blank=True, through='AUsers')
Then I do:
% ./manage.py schemamigration app --auto
Not totally surprising, it tells me it is going to drop the original auto-created through table and create a new one for AUsers
. What's the best practice at this point? Is there a decent way to migrate to the new through
table? Do I use db_table
in Meta? Do I just not use the through=...
right away... then do a schemamigration --auto
, then a datamigration
to copy the current table (somehow, not sure...) and then add the through
relation and let it kill the table?
What's the trick here? Is this really that hard?