Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #316 -- Added special-case for MySQL microseconds, so that it d…

…oesn't throw a warning when microseconds are given.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@497 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit bc00059b2fcc4e59c2bef59700a8a78a3e014948 1 parent 2c3067b
@adrianholovaty adrianholovaty authored
Showing with 8 additions and 0 deletions.
  1. +8 −0 django/core/meta/fields.py
View
8 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 @@ def pre_save(self, value, add):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.