Opened 17 months ago
Last modified 17 months ago
#34680 closed Uncategorized
inspectdb on mysql timestamp fields leads to timezone issues — at Version 1
Reported by: | Neil McKenzie | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.2 |
Severity: | Normal | Keywords: | inspectdb, mysql, timestamp |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.