#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

Description

Hello,

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,
Vlad

Change History (2)

comment:1 Changed 15 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Is this related to #15725?

comment:2 Changed 15 months ago by aaugustin

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

Aren't you confusing default and initial too?

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