Opened 5 years ago

Closed 5 years ago

#22160 closed Bug (needsinfo)

TimeField default argument not working.

Reported by: vlad.dragos.002@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
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



The problem is that i have the field definition like this:
pickup_time_from = models.TimeField(default=datetime.time(hour=9))

And when I try to validate the model through a ModelForm it give me the error that the field is required.
I also tried the following:
pickup_time_from = models.TimeField(default=datetime.time(hour=9), blank=True)
But it throws the following exception:
null value in column "pickup_time_from" violates not-null constraint

Hope this helps,
Best regards,

Change History (2)

comment:1 Changed 5 years ago by Claude Paroz

Is this related to #15725?

comment:2 Changed 5 years ago by Aymeric Augustin

Resolution: needsinfo
Status: newclosed

Aren't you confusing default and initial too?

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