问题描述
除了向模型添加/删除/修改字段外,当我向模型添加或修改方法时,Django还会检测到更改.
In addition to adding/deleting/modifying field to model, Django also detects changes when I add or modify methods to the model.
所以我的问题是,每次更改或在模型中添加新方法时,我都应该运行makemigrations
吗?
So my question is should I run makemigrations
every time I change or add a new method in models ?
推荐答案
添加/更改模型方法时,无需运行./manage makemigrations
和./manage.py migrate
.
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.
这篇关于Django:什么时候运行makemigrations?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!