#30337: Django Admin - Migrations: default value for models.DateTime() with
auto_add_now=True
-----------------------------------------+------------------------
Reporter: jillesme | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello everyone,
In a personal project I created a model, populated the database and later
realised that I needed a `created` field on it. So I added
models.DateTime() with auto_add_now=True. When running the migrations I
got this prompt:
```
You are trying to add the field 'created' with 'auto_now_add=True' to
squad without a default; the database needs something to populate existing
rows.
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
You can accept the default 'timezone.now' by pressing 'Enter' or you can
provide another value.
The datetime and django.utils.timezone modules are available, so you can
do e.g. timezone.now
Type 'exit' to exit this prompt
[default: timezone.now] >>>
You are trying to add the field 'created' with 'auto_now_add=True' to
squadapplication without a default; the database needs something to
populate existing rows.
// Now I had to run it again and do timezone.now() myself
```
I believe that the default should be `timezone.now()` (invoking the
function). When the default is `timezone.now` - without invoking it - it
will actually not work and not throw an error.
Is this a know bug or a feature? If it's a bug I'd like to contribute
myself to fix it :)
--
Ticket URL: <https://code.djangoproject.com/ticket/30337>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.4dea2766184eb132357e789d27c4b6b2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.