Django - syncdb doesn't create tables

后端 未结 2 2004
夕颜
夕颜 2020-12-19 03:45

I added a many-to-many field to an existing model and was expecting syncdb to create a new table, but there\'s nothing there. This is what the model looks like:

2条回答
  •  醉话见心
    2020-12-19 04:32

    The syncdb command does not create many to many tables for existing models by design. This decision is explained on ticket 2229.

    That leaves you with a few options.

    • If you don't have any data in your Book model, drop the table and rerun syncdb. Django will recreate the book table and the many to many table.
    • Use the dbshell command, and create the many to many joining table using the output of sql myapp.
    • If you're doing multiple schema migrations with Django, make friends with South.

提交回复
热议问题