#23365 closed New feature (fixed)
Add support for serializing timezone-aware datetimes in migrations
Reported by: | rasca | Owned by: | Rudy Mutter |
---|---|---|---|
Component: | Migrations | Version: | 1.7-rc-3 |
Severity: | Normal | Keywords: | migration |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When adding a new not nullable DateTimeField to a model it prompts you to select a default:
You are trying to add a non-nullable field '...' to user without a default; we can't do that (the database needs something to populate existing rows). Please select a fix: 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 The datetime module is available, so you can do e.g. datetime.date.today()
If you have USE_TZ = True
then using datetime.date.today()
and executing the migration results in:
RuntimeWarning: DateTimeField ... received a naive datetime (...) while time zone support is active.
I think we should be using:
>>> django.utils.timezone.now Invalid input: name 'django' is not defined
but it's not possible. I think we should add the django namespace to the prompt and use a different message in case USE_TZ = True
Change History (11)
comment:1 by , 10 years ago
comment:3 by , 10 years ago
Severity: | Release blocker → Normal |
---|
This is not a release blocker - it does not crash, or cause data loss, it's merely a poor example in an example prompt. Demoting.
That said, we should make the prompt allow for the django timezone-aware stuff to work.
comment:4 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → New feature |
comment:5 by , 10 years ago
Easy pickings: | set |
---|
comment:6 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 10 years ago
Has patch: | set |
---|
Just created a pull request: https://github.com/django/django/pull/3185
comment:8 by , 10 years ago
Easy pickings: | unset |
---|---|
Summary: | makemigrations with a new not nullable DateTimeField leads to RuntimeWarning → Add support for serializing timezone-aware datetimes in migrations |
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I've set this as a Release Blocker because it leads users to create code that raises a RuntimeWarning.