将ManyToManyField迁移为null true,空白为true,无法识别 [英] Migrating ManyToManyField to null true, blank true, isn't recognized
问题描述
我已经从
standard = models.ManyToManyField(Standard)
to
standard = models.ManyToManyField(Standard, blank=True, null=True)
此应用程序的南方模式迁移无法识别改变?
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将创建一个标准
属性在您的模型实例为方便起见,没有实际的列代表它可以被置空。根据定义,关系总是可以是零个实例。
That behavior is correct: null
doesn't mean anything at the database level when used with a ManyToManyField
. The invocation 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 the admin app, 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 would 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 true,空白为true,无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!