#34680 closed Uncategorized (duplicate)

inspectdb on mysql timestamp fields leads to timezone issues

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 (2)

comment:1 by Neil McKenzie , 18 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 18 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #19312. This caveat is already documented.

Note: See TracTickets for help on using tickets.
Back to Top