更改Django模型的related_name属性是否需要向南迁移? [英] Does changing a django models related_name attribute require a south migration?
问题描述
我有一个带有外键的简单Django模型
I have a simple django model with a ForeignKey
class FooModel(models.Model):
foo = models.ForeignKey('Foo', related_name="foo_choices")
bar = models.CharField(max_length=50)
related_name属性已经存在,但是我想更改它。此更改是否需要任何形式的迁移?当我在修改related_name之后运行schemamigration管理命令时,我得到似乎什么都没有改变,但我想验证。
The related_name attribute exists already, but I'd like to change it. Will this change require a migration of any kind? When I run the schemamigration management command after modifying the related_name I get the "Nothing seems to have changed" but I wanted to verify.
推荐答案
否您不需要迁移。
相关名称是用于从相关对象返回到该对象(反向关系)的关系的名称。
Related name is the name to use for the relation from the related object back to this one (the reverse relationship).
related_name
与数据库无关。它由Django的ORM占用以获取查询集结果,因此,如果在模型字段中更改 related_name
属性,则无需迁移。
related_name
has nothing to do with the database. It is consumed by the Django's ORM to fetch queryset results, so you dont need a migration if you change the related_name
attribute on a models' field.
这篇关于更改Django模型的related_name属性是否需要向南迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!