将 ManyToManyField 迁移到 null tr​​ue,空白 true,无法识别 [英] Migrating ManyToManyField to null true, blank true, isn't recognized

查看:18
本文介绍了将 ManyToManyField 迁移到 null tr​​ue,空白 true,无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对

standard = models.ManyToManyField(Standard)

standard = models.ManyToManyField(Standard, blank=True, null=True)

此应用程序的 South schemamigration 无法识别更改?

South schemamigration for this app doesn't recognize the change?

类似于这个问题,没有答案:南迁移和多对五月字段的变化

Similar to this question, which is unanswered: South migrations and changes to many-to-may fields

推荐答案

该行为是正确的:null 在与 ManyToManyField.ManyToManyField 的声明会导致创建一个中间表来保存关系,尽管 Django 会为您的方便在您的模型实例上创建一个 standard 属性,但没有表示它的实际列可以为空.根据定义,关系的实例总是可以为零.

That behavior is correct: null doesn't mean anything at the database level when used with a ManyToManyField. The declaration of a ManyToManyField causes the creation of an intermediate table to hold the relationship, and although Django will create a standard attribute on your model instance for your convenience, there is no actual column representing it that could be nulled. By definition there can always be zero instances of the relationship.

blank=False 确实会对验证产生影响(例如,在使用管理应用等模型表单时),迫使用户至少选择一种关系.

blank=False, though, does have an effect on validation (when using model forms like the admin app, for example), forcing the user to choose at least one relation.

(请注意,Django 的内置迁移系统会为模型的任何更改创建迁移,无论它是否影响数据库.因此,此更改可能导致迁移,但不会影响数据库或者您是否可以拥有零个关系实例.)

(Note that Django's built-in migration system creates migrations for just about any change to a model, regardless of whether it affects the database or not. So this change could lead to a migration, but it wouldn't affect the database or whether or not you could have zero instances of the relationship.)

这篇关于将 ManyToManyField 迁移到 null tr​​ue,空白 true,无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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