Django:什么时候运行makemigrations? [英] Django: When to run makemigrations?

查看:65
本文介绍了Django:什么时候运行makemigrations?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了向模型添加/删除/修改字段外,当我向模型添加或修改方法时,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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆