summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/core/meta/fields.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py
index 6743ed79a9..87b5a34fa0 100644
--- a/django/core/meta/fields.py
+++ b/django/core/meta/fields.py
@@ -299,6 +299,10 @@ class DateTimeField(DateField):
def get_db_prep_save(self, value):
# Casts dates into string format for entry into database.
if value is not None:
+ # MySQL will throw a warning if microseconds are given, because it
+ # doesn't support microseconds.
+ if settings.DATABASE_ENGINE == 'mysql':
+ value = value.replace(microsecond=0)
value = str(value)
return Field.get_db_prep_save(self, value)
@@ -493,6 +497,10 @@ class TimeField(Field):
def get_db_prep_save(self, value):
# Casts dates into string format for entry into database.
if value is not None:
+ # MySQL will throw a warning if microseconds are given, because it
+ # doesn't support microseconds.
+ if settings.DATABASE_ENGINE == 'mysql':
+ value = value.replace(microsecond=0)
value = str(value)
return Field.get_db_prep_save(self, value)