简体   繁体   English

Django DateTimeField定义为blank = True,null = True但不允许null

[英]Django DateTimeField Defined as blank=True, null=True but doesn't allow null

I have a DateTimeField in one of my Django models. 我在我的一个Django模型中有一个DateTimeField。

    completed_date = models.DateTimeField('date completed', blank=True, null=True)

I've defined it to allow blank and null values. 我已将其定义为允许空值和空值。 However, when I try to create an instance of the model, I get the following error: 但是,当我尝试创建模型的实例时,我收到以下错误:

IntegrityError at /admin/tasks/project/add/ / admin / tasks / project / add /中的IntegrityError

tasks_project.completed_date may not be NULL tasks_project.completed_date可能不是NULL

I'm using Django 1.25 and Python 2.7. 我正在使用Django 1.25和Python 2.7。 Anyone know why this is happening? 任何人都知道为什么会这样吗? Is there anything I can do to fix this? 有什么办法可以解决这个问题吗?

I found a ticket that describes the same problem , but it was closed as fixed 4 years ago, so I assume it must have been integrated into Django by now! 我找到了一张描述同样问题 ,但它在4年前被修复了,所以我认为它现在必须已经集成到Django中了!

django syncdb and an updated model django syncdb和更新的模型

from that question/answer: 从那个问题/答案:

Django doesn't support migrations out of the box. Django不支持开箱即用的迁移。 There is a pluggable app for Django that does exactly that though, and it works great. Django有一个可插拔的应用程序可以做到这一点,而且效果很好。 It's called South. 它被称为南方。

http://south.aeracode.org/

Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. 没有在一段时间内使用过django,但我似乎记得syncdb确实在db表上执行alter命令。 you have to drop the table then run again and it will create again. 你必须放弃表然后再次运行它将再次创建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM