Fixed #27676 -- Allowed BLOB/TEXT defaults on MariaDB 10.2.1+.

This commit is contained in:
Adam Johnson 2019-08-14 15:52:04 +01:00 committed by Mariusz Felisiak
parent 8a281aa7fe
commit 7da6a28a44
3 changed files with 20 additions and 9 deletions

View File

@ -16,11 +16,11 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor):
self.geometry_sql = []
def skip_default(self, field):
return (
super().skip_default(field) or
# Geometry fields are stored as BLOB/TEXT and can't have defaults.
isinstance(field, GeometryField)
)
# Geometry fields are stored as BLOB/TEXT, for which MySQL and MariaDB
# < 10.2.1 don't support defaults.
if isinstance(field, GeometryField) and not self._supports_limited_data_type_defaults:
return True
return super().skip_default(field)
def column_sql(self, model, field, include_default=False):
column_sql = super().column_sql(model, field, include_default)

View File

@ -130,9 +130,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
'UUIDField': 'char(32)',
}
# For these columns, MySQL doesn't:
# - accept default values and implicitly treats these columns as nullable
# - support a database index
# For these data types:
# - MySQL and MariaDB < 10.2.1 don't accept default values and implicitly
# treat them as nullable
# - all versions of MySQL and MariaDB don't support full width database
# indexes
_limited_data_types = (
'tinyblob', 'blob', 'mediumblob', 'longblob', 'tinytext', 'text',
'mediumtext', 'longtext', 'json',

View File

@ -48,7 +48,16 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
return db_type is not None and db_type.lower() in self.connection._limited_data_types
def skip_default(self, field):
return self._is_limited_data_type(field)
if not self._supports_limited_data_type_defaults:
return self._is_limited_data_type(field)
return False
@property
def _supports_limited_data_type_defaults(self):
# Only MariaDB >= 10.2.1 supports defaults for BLOB and TEXT.
if self.connection.mysql_is_mariadb:
return self.connection.mysql_version >= (10, 2, 1)
return False
def add_field(self, model, field):
super().add_field(model, field)