Django: When to run makemigrations?

后端 未结 2 1016
孤街浪徒
孤街浪徒 2021-02-15 11:06

In addition to adding/deleting/modifying field to model, Django also detects changes when I add or modify methods to the model.

So my question is should I run make

相关标签:
2条回答
  • 2021-02-15 11:49

    When you add/change model methods, then you don't need to run ./manage makemigrations and ./manage.py migrate.

    But whenever you edit your model fields (adding a new one, changing an existing one or altering any of the arguments it takes) then you should always run migrations.

    0 讨论(0)
  • 2021-02-15 12:05

    First of all,

    ./manage makemigrations

    will create (migration_number).py files in your app migrations folders. These lines of code are nothing but statements which help in creating actual fields in your respective database similar to SQL statements.

    In order to execute the migration which was created using the previous command, we will run the following command,

    ./manage.py migrate

    On migrate your new model fields will be reflected in database if there are no errors

    0 讨论(0)
提交回复
热议问题