Django: When to run makemigrations?

╄→гoц情女王★ 提交于 2019-12-04 23:00:08

问题


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 makemigrations every time I change or add a new method in models ?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/43017095/django-when-to-run-makemigrations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!