diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-08-12 18:14:06 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-10-28 15:06:58 +0100 |
| commit | 22da5f8817ffff3917bcf8a652dce84f382c9202 (patch) | |
| tree | 11e5888b710ce4969a02d7a1574e3739c7da5f68 /django | |
| parent | 9e746c13e81241fbf1ae64ec118edaa491790046 (diff) | |
Fixed #19716 -- Added support for microseconds with MySQL 5.6.4 and up
Thanks erik@cederstrand.dk for the report and Tim Graham for the review.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/mysql/base.py | 7 | ||||
| -rw-r--r-- | django/db/backends/mysql/creation.py | 10 |
2 files changed, 14 insertions, 3 deletions
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index f0e184dde3..fcdee1bbd3 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -79,7 +79,7 @@ def adapt_datetime_with_timezone_support(value, conv): default_timezone = timezone.get_default_timezone() value = timezone.make_aware(value, default_timezone) value = value.astimezone(timezone.utc).replace(tzinfo=None) - return Thing2Literal(value.strftime("%Y-%m-%d %H:%M:%S"), conv) + return Thing2Literal(value.strftime("%Y-%m-%d %H:%M:%S.%f"), conv) # MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like # timedelta in terms of actual behavior as they are signed and include days -- @@ -175,7 +175,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): supports_forward_references = False # XXX MySQL DB-API drivers currently fail on binary data on Python 3. supports_binary_field = six.PY2 - supports_microsecond_precision = False supports_regex_backreferencing = False supports_date_lookup_using_string = False can_introspect_binary_field = False @@ -211,6 +210,10 @@ class DatabaseFeatures(BaseDatabaseFeatures): return self._mysql_storage_engine != 'MyISAM' @cached_property + def supports_microsecond_precision(self): + return self.connection.mysql_version >= (5, 6, 4) + + @cached_property def has_zoneinfo_database(self): # MySQL accepts full time zones names (eg. Africa/Nairobi) but rejects # abbreviations (eg. EAT). When pytz isn't installed and the current diff --git a/django/db/backends/mysql/creation.py b/django/db/backends/mysql/creation.py index fd3a595eb4..40d9251235 100644 --- a/django/db/backends/mysql/creation.py +++ b/django/db/backends/mysql/creation.py @@ -1,4 +1,5 @@ from django.db.backends.creation import BaseDatabaseCreation +from django.utils.functional import cached_property class DatabaseCreation(BaseDatabaseCreation): @@ -6,7 +7,7 @@ class DatabaseCreation(BaseDatabaseCreation): # types, as strings. Column-type strings can contain format strings; they'll # be interpolated against the values of Field.__dict__ before being output. # If a column type is set to None, it won't be included in the output. - data_types = { + _data_types = { 'AutoField': 'integer AUTO_INCREMENT', 'BinaryField': 'longblob', 'BooleanField': 'bool', @@ -33,6 +34,13 @@ class DatabaseCreation(BaseDatabaseCreation): 'UUIDField': 'char(32)', } + @cached_property + def data_types(self): + if self.connection.features.supports_microsecond_precision: + return dict(self._data_types, DateTimeField='datetime(6)', TimeField='time(6)') + else: + return self._data_types + def sql_table_creation_suffix(self): suffix = [] test_settings = self.connection.settings_dict['TEST'] |
