diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index fcdee1bbd3..3a34aeb35d 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -211,7 +211,9 @@ class DatabaseFeatures(BaseDatabaseFeatures): @cached_property def supports_microsecond_precision(self): - return self.connection.mysql_version >= (5, 6, 4) + # See https://github.com/farcepest/MySQLdb1/issues/24 for the reason + # about requiring MySQLdb 1.2.5 + return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5) @cached_property def has_zoneinfo_database(self): diff --git a/docs/ref/databases.txt b/docs/ref/databases.txt index 63cb5f279e..f129058e98 100644 --- a/docs/ref/databases.txt +++ b/docs/ref/databases.txt @@ -503,7 +503,11 @@ Fractional seconds support for Time and DateTime fields MySQL 5.6.4 and later can store fractional seconds, provided that the column definition includes a fractional indication (e.g. ``DATETIME(6)``). -Earlier versions do not support them at all. +Earlier versions do not support them at all. In addition, versions of MySQLdb +older than 1.2.5 have `a bug`_ that also prevents the use of fractional seconds +with MySQL. + +.. _a bug: https://github.com/farcepest/MySQLdb1/issues/24 Django will not upgrade existing columns to include fractional seconds if the database server supports it. If you want to enable them on an existing database, @@ -521,7 +525,8 @@ or using a :class:`~django.db.migrations.operations.RunSQL` operation in a ``time`` values when using the MySQL backend. Now it lets the database decide whether it should drop that part of the value or not. By default, new ``DateTimeField`` or ``TimeField`` columns are now created with fractional - seconds support on MySQL 5.6.4 or later. + seconds support on MySQL 5.6.4 or later with either mysqlclient or + MySQLdb 1.2.5 or later. ``TIMESTAMP`` columns ~~~~~~~~~~~~~~~~~~~~~