Opened 9 years ago
Closed 9 years ago
#25005 closed Bug (fixed)
DateField, DateTimeField defaults needed even when auto_now=True
Reported by: | monobotsoft | Owned by: | Iacopo Spalletti |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | DateField, DateTimeField, TimeField |
Cc: | me@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When you create a new DateField on a model even when it has auto_now=True.
./manage.py makemigrations asks for a default value
This is a low priority bug since its so easylly solved using default=timezone.now
Attachments (1)
Change History (14)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 9 years ago
Attachment: | ticket_25005.patch added |
---|
comment:2 by , 9 years ago
Cc: | added |
---|---|
Owner: | changed from | to
Status: | new → assigned |
follow-up: 6 comment:3 by , 9 years ago
Changing autodetector is not a problem.
But...
When we have some model, then adding DateField or DateTimeField with auto_now/auto_now_add, and disable promting for default, it throws integrity errors for null. So seems it not works on existing objects. Is that normal behavior or it is a bug?
comment:4 by , 9 years ago
So, seems there changes in effective_default
are needed, so I'm going this way
comment:6 by , 9 years ago
Replying to coldmind:
When we have some model, then adding DateField or DateTimeField with auto_now/auto_now_add, and disable promting for default, it throws integrity errors for null. So seems it not works on existing objects. Is that normal behavior or it is a bug?
That's expected behavior. auto_now
and auto_now_add
are purely handled in Python (default
too, but on a different level) and thus don't influence the default value for the database.
As far as I can tell, combining auto_now
, auto_now_add
and default
is not allowed, since those three options are supposed to be mutual exclusive: https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.DateField
comment:7 by , 9 years ago
Keywords: | TimeField added |
---|---|
Version: | 1.8 → master |
Opened new PR - https://github.com/django/django/pull/4902
This will not backported to 1.8
comment:8 by , 9 years ago
Patch needs improvement: | set |
---|
comment:9 by , 9 years ago
Owner: | changed from | to
---|
Assigning to myself to bring PR in mergeable state
comment:10 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:11 by , 9 years ago
Patch needs improvement: | set |
---|
The new test isn't passing on Oracle.
comment:12 by , 9 years ago
Patch needs improvement: | unset |
---|
Tests to reproduce the issue