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

2024-06-11 10:51:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我的一个Django模型中有一个DateTimeField。

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

我将其定义为允许空白和空值。但是,当我尝试创建模型的实例时,会出现以下错误:

IntegrityError at /admin/tasks/project/add/

tasks_project.completed_date may not be NULL

我使用的是Django 1.25和Python 2.7。有人知道为什么会这样吗?我能做些什么来解决这个问题吗?

我发现了一个ticket that describes the same problem,但它在4年前就已经关闭了,所以我想它现在一定已经集成到Django中了!


Tags: django实例模型projecttruedate定义models
1条回答
网友
1楼 · 发布于 2024-06-11 10:51:42

django syncdb and an updated model

从这个问题/答案:

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.

^{}

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.

相关问题 更多 >