summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/operations.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/mysql/operations.py')
-rw-r--r--django/db/backends/mysql/operations.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py
index fd468cb182..bc53f59ec5 100644
--- a/django/db/backends/mysql/operations.py
+++ b/django/db/backends/mysql/operations.py
@@ -77,7 +77,10 @@ class DatabaseOperations(BaseDatabaseOperations):
timedelta.days, timedelta.seconds, timedelta.microseconds), []
def format_for_duration_arithmetic(self, sql):
- return 'INTERVAL %s MICROSECOND' % sql
+ if self.connection.features.supports_microsecond_precision:
+ return 'INTERVAL %s MICROSECOND' % sql
+ else:
+ return 'INTERVAL FLOOR(%s / 1000000) SECOND' % sql
def drop_foreignkey_sql(self):
return "DROP FOREIGN KEY"
@@ -146,6 +149,9 @@ class DatabaseOperations(BaseDatabaseOperations):
else:
raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
+ if not self.connection.features.supports_microsecond_precision:
+ value = value.replace(microsecond=0)
+
return six.text_type(value)
def value_to_db_time(self, value):