Fixed #27676 -- Allowed BLOB/TEXT defaults on MariaDB 10.2.1+.
This commit is contained in:
parent
8a281aa7fe
commit
7da6a28a44
|
@ -16,11 +16,11 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor):
|
||||||
self.geometry_sql = []
|
self.geometry_sql = []
|
||||||
|
|
||||||
def skip_default(self, field):
|
def skip_default(self, field):
|
||||||
return (
|
# Geometry fields are stored as BLOB/TEXT, for which MySQL and MariaDB
|
||||||
super().skip_default(field) or
|
# < 10.2.1 don't support defaults.
|
||||||
# Geometry fields are stored as BLOB/TEXT and can't have defaults.
|
if isinstance(field, GeometryField) and not self._supports_limited_data_type_defaults:
|
||||||
isinstance(field, GeometryField)
|
return True
|
||||||
)
|
return super().skip_default(field)
|
||||||
|
|
||||||
def column_sql(self, model, field, include_default=False):
|
def column_sql(self, model, field, include_default=False):
|
||||||
column_sql = super().column_sql(model, field, include_default)
|
column_sql = super().column_sql(model, field, include_default)
|
||||||
|
|
|
@ -130,9 +130,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
'UUIDField': 'char(32)',
|
'UUIDField': 'char(32)',
|
||||||
}
|
}
|
||||||
|
|
||||||
# For these columns, MySQL doesn't:
|
# For these data types:
|
||||||
# - accept default values and implicitly treats these columns as nullable
|
# - MySQL and MariaDB < 10.2.1 don't accept default values and implicitly
|
||||||
# - support a database index
|
# treat them as nullable
|
||||||
|
# - all versions of MySQL and MariaDB don't support full width database
|
||||||
|
# indexes
|
||||||
_limited_data_types = (
|
_limited_data_types = (
|
||||||
'tinyblob', 'blob', 'mediumblob', 'longblob', 'tinytext', 'text',
|
'tinyblob', 'blob', 'mediumblob', 'longblob', 'tinytext', 'text',
|
||||||
'mediumtext', 'longtext', 'json',
|
'mediumtext', 'longtext', 'json',
|
||||||
|
|
|
@ -48,7 +48,16 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
return db_type is not None and db_type.lower() in self.connection._limited_data_types
|
return db_type is not None and db_type.lower() in self.connection._limited_data_types
|
||||||
|
|
||||||
def skip_default(self, field):
|
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):
|
def add_field(self, model, field):
|
||||||
super().add_field(model, field)
|
super().add_field(model, field)
|
||||||
|
|
Loading…
Reference in New Issue