Python Django(1.9)makemigrations不';在布尔字段上,t get Blank=True
我有以下型号:Python Django(1.9)makemigrations不';在布尔字段上,t get Blank=True,python,django,database,model,Python,Django,Database,Model,我有以下型号: class Site(models.Model): """ Model for a site entry @author: Leonardo Pessoa @since: 05/09/2016 """ from decimal import Decimal consolidated_financials = models.BooleanField(blank=True) type
class Site(models.Model):
"""
Model for a site entry
@author: Leonardo Pessoa
@since: 05/09/2016
"""
from decimal import Decimal
consolidated_financials = models.BooleanField(blank=True)
type = models.ForeignKey(Type)
tier1_business = models.ForeignKey(Business, limit_choices_to = {'tier': 1}, related_name='%(class)s_tier1')
请注意,consolidated_financials
字段现在有blank=True
语句。
这是新列入的。当我运行makemigrations时,它没有得到更改,但当我添加到finance\u manager\u sso
时,它工作正常
布尔字段是否有特定的限制
谢谢不接受null=True,而是使用
Jacob Maristany的一篇关于Programmers.se的文章解释了这口井背后的原因
通过在布尔字段中允许空值,可以将预期的二进制表示(真/假)转换为三态表示(真、假、空),其中“空”项是不确定的
有关详细讨论,请参见
布尔字段不使用blank
参数。相反,它是要True
。传递blank=False
无效,因此迁移自动检测器不会检测到字段的任何更改,也不会创建任何迁移
由于blank
参数由IntegerField
使用,因此传入blank=False
将导致序列化字段发生更改。迁移自动检测器将检测该更改并创建迁移(即使该更改不会影响数据库) 相关:如果您试图允许“已检查”、“未检查”或“未指定”值,则OP可能正在查找null=True
。BooleanField不接受null=True,而是使用NullBooleanField。谢谢你的帮助!啊,真有意思。好发现!有人知道为什么布尔字段不能/不应该使用null=True
?当然,除此之外,文件中也有说明。:)对序列化字段的任何更改都将创建迁移,即使该更改不会影响数据库。这允许通过RunPython
操作在迁移计划中的特定点使用字段选项。你可以很容易地用blank
参数测试,例如IntegerField
,OP也注意到了这一点。@knbk-是的,我在回答后也意识到了这一点(这是漫长的一天),虽然我不能再删除我的答案,但还是给了你的答案一个更高的分数