Opened 10 years ago

Closed 10 years ago

#1043 closed defect (invalid)

DateField doesn't work with blank=True

Reported by: wojtek@… Owned by: adrian
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: UI/UX:

Description

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 10 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 10 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

Yeah, you need null=True on that DateField.

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