Browse files

fix datetime colume truncated error

error esg:
  DatabaseError: Data truncated for column <applied> at row 1
  • Loading branch information...
Robert Lu Robert Lu
Robert Lu authored and Robert Lu committed Feb 27, 2017
1 parent 24a5ee7 commit 93c7b38089700b2ca7a03054ed902e111f2cb10c
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/mysql/connector/django/
@@ -43,6 +43,22 @@ def date_extract_sql(self, lookup_type, field_name):
return "EXTRACT({0} FROM {1})".format(
lookup_type.upper(), field_name)
def adapt_datetimefield_value(self, value):
if value is None:
return None
# MySQL doesn't support tz-aware datetimes
if timezone.is_aware(value):
if settings.USE_TZ:
value = timezone.make_naive(value, self.connection.timezone)
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 force_text(value)
def date_trunc_sql(self, lookup_type, field_name):
"""Returns SQL simulating DATE_TRUNC

0 comments on commit 93c7b38

Please sign in to comment.