Opened 4 years ago

Closed 4 years ago

#24678 closed Bug (invalid)

auto_add and auto_add_now cannot be used together in DateTimeField definition

Reported by: Moritz Pfeiffer Owned by: nobody
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords: DateTimeField, auto_now, auto_now_add
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I use auto_now=True in combination with auto_now_add=True on a models.DateTimeField I get the following error:
python manage.py check:
(fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may be present.

See the attached project with a simple model illustrating this issue.

Attachments (1)

auto_now_add_test.zip (10.1 KB) - added by Moritz Pfeiffer 4 years ago.
Simple Django 1.8 project with a single model illustrating this issue

Download all attachments as: .zip

Change History (2)

Changed 4 years ago by Moritz Pfeiffer

Attachment: auto_now_add_test.zip added

Simple Django 1.8 project with a single model illustrating this issue

comment:1 Changed 4 years ago by Claude Paroz

Resolution: invalid
Status: newclosed

Yes, this was indeed enforced in #21798. The error message is right, you are not supposed to set both parameters. In your example use case, auto_now is sufficient.

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