Opened 15 months ago

Last modified 15 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 Neil McKenzie )

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.

Change History (1)

comment:1 by Neil McKenzie , 15 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top