Adding a “through” table to django field and migrating with South?

后端 未结 3 1909
-上瘾入骨i
-上瘾入骨i 2021-01-04 01:41

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 =         


        
3条回答
  •  悲哀的现实
    2021-01-04 02:06

    If anyone comes across this question when trying to do the same thing with the moderns migration framework, here are the steps:

    1. Create a new model class that exactly matches the built-in through table
    2. Use the Meta class to set the table name to match the existing table
    3. Generate a migration, which will create the new table and set it as the through for the field.
    4. Without running that migration, edit it to wrap it in a migrations. SeparateDatabaseAndState migration, where the auto-generated steps are in the state_operations field and the database operations are empty.
    5. Modify your through table, as required, making sure to generate new migrations as normal.

提交回复
热议问题