Opened 13 years ago

Closed 13 years ago

#1043 closed defect (invalid)

DateField doesn't work with blank=True

Reported by: wojtek@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I created the following model:
class Event(meta.Model):

heading = meta.CharField(maxlength=256)
description = meta.TextField()
added = meta.DateField(auto_now_add = True)
remind = meta.DateField(blank = True)
file = meta.FileField(upload_to = MEDIA_ROOT, blank = True)

If I don't fill out the 'remind' field in the form - I get the following error:
ERROR: null value in column "remind" violates not-null constraint INSERT INTO "crm_events" ("heading","description","added","remind","file") VALUES ('foo','bar','2005-12-12',NULL,)

So apparently that column should be set to NOT null automagically.

Change History (2)

comment:1 Changed 13 years ago by Esaj

You need to add null=True as well as blank=True. I wonder if this should be done automatically when blank=True is specified, since that is what is wanted in 90% of cases?

comment:2 Changed 13 years ago by Adrian Holovaty

Resolution: invalid
Status: newclosed

Yeah, you need null=True on that DateField.

Note: See TracTickets for help on using tickets.
Back to Top