#34680: inspectdb on mysql timestamp fields leads to timezone issues
-------------------------------------+-------------------------------------
Reporter: neilbags | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: inspectdb, mysql, | Triage Stage:
timestamp | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by neilbags:
Old description:
> When using inspectdb on a MySQL database timestamp columns in MySQL are
> generated as DateTime fields in Django models. On the surface this
> appears to work, however, MySQL makes timezone adjustments for timestamps
> and not for datetimes.
>
> Since Django expects these columns to be datetime, if the server timezone
> is changed, incorrect dates/times are returned. I saw this in the wild
> with
> some created_at and updated_at columns that were created as timestamp
> fields by Laravel.
>
> I'm not sure if this is something that should be fixed. Maybe the
> inspectdb feature could give a warning when encountering these columns,
> or this could be documented as a caveat in the section on inspectdb
> and/or the howto on dealing with legacy databases.
New description:
When using inspectdb on a MySQL database timestamp columns are generated
as DateTime fields in Django models. On the surface this appears to work,
however, MySQL makes timezone adjustments for timestamps and not for
datetimes.
Since Django expects these columns to be datetime, if the server timezone
is changed, incorrect dates/times are returned. I saw this in the wild
with
some created_at and updated_at columns that were created as timestamp
fields by Laravel.
I'm not sure if this is something that should be fixed. Maybe the
inspectdb feature could give a warning when encountering these columns, or
this could be documented as a caveat in the section on inspectdb and/or
the howto on dealing with legacy databases.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34680#comment:1>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070188fa9ef900-27431d58-85b6-4489-b780-c6b9b0a565c6-000000%40eu-central-1.amazonses.com.