2011-03-20 92 views
7

我有一个DateTimeField字段在我的Django的车型之一。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的!

+1

你加空=做创建该领域的执行syncdb后,是真的吗? – Tiago 2011-03-20 12:06:39

+0

是的。但我再次运行syncdb。 – 2011-03-20 12:18:59

+0

除非您删除运行syncdb的表不会更改字段上的约束。您需要使用迁移工具(如南)或删除该表,然后再次运行syncdb。 – DTing 2011-03-20 12:30:01

回答

9

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.

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.

+2

我第二南。这是非常快,易于安装和起床,并运行它。最好的部分:没有写入迁移文件(到目前为止)。 – Marcin 2011-05-28 16:21:42

相关问题