mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
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 = []
|
||||
|
||||
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)
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user