Django DateTimeField() and timezone.now()
Django ORM converts DateTimeField
to Timestamp
in mysql. You can confirm that by looking at the raw sql doing ./manage.py sqlall <appname>
In mysql timestamp
does not store milliseconds.
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.
It is a bug in MySql which appears to be fixed in v5.6.4, The Bug
Noted in 5.6.4 changelog.
MySQL now supports fractional seconds for TIME, DATETIME, and
TIMESTAMP values, with up to microsecond precision.
Django 1.8 now supports milliseconds.
Previously, Django truncated fractional seconds from datetime and time values when using the MySQL backend. Now it lets the database decide whether it should drop that part of the value or not
According to the mysql developer site:
A DATETIME or TIMESTAMP value can include a trailing fractional seconds part in up to microseconds (6 digits) precision. Although this fractional part is recognized, it is discarded from values stored into DATETIME or TIMESTAMP columns.