开发者

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

开发者 https://www.devze.com 2023-02-18 09:30 出处:网络
I have a DateTimeField in one of my Django models. completed_date = models.DateTimeField(\'date completed\', blank=True, null=True)

I have a DateTimeField in one of my Django models.

    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 mod开发者_JS百科el, I get the following error:

IntegrityError at /admin/tasks/project/add/

tasks_project.completed_date may not be NULL

I'm using Django 1.25 and 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!


django syncdb and an updated model

from that question/answer:

Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. 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. you have to drop the table then run again and it will create again.

0

精彩评论

暂无评论...
验证码 换一张
取 消