8

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 model, 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!

Mark Nenadov
  • 6,421
  • 5
  • 24
  • 32
  • 1
    Did you add the null=True after doing the syncdb that created the field? – Tiago Mar 20 '11 at 12:06
  • unless you delete the table running syncdb isn't going to change the constraint on the fields. You need to use a migration tool, like south or delete that table and then run syncdb again. – dting Mar 20 '11 at 12:30

1 Answers1

10

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.

Community
  • 1
  • 1
dting
  • 38,604
  • 10
  • 95
  • 114
  • 2
    I second south. It was very quick and easy to install and get up and running with it. Best part: no writing of migration files (so far). – Marcin May 28 '11 at 16:21