Opened 11 years ago
Closed 11 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)
Change History (2)
by , 11 years ago
| Attachment: | auto_now_add_test.zip added | 
|---|
comment:1 by , 11 years ago
| Resolution: | → invalid | 
|---|---|
| Status: | new → closed | 
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.
Simple Django 1.8 project with a single model illustrating this issue