From d6c868a184e01f44302e8d31130fe1321208a6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Kr=C3=B6nke?= Date: Tue, 28 Nov 2023 15:06:06 +0100 Subject: [PATCH] Fixed #35000 -- Skipped declaring empty string defaults on BLOB/TEXT field on MySQL. Empty string defaults are redundant on MySQL and prevent use of ALGORITHM=INSTANT. --- django/db/backends/mysql/schema.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py index 905a26bfba..8651348ee2 100644 --- a/django/db/backends/mysql/schema.py +++ b/django/db/backends/mysql/schema.py @@ -69,12 +69,22 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): and db_type.lower() in self.connection._limited_data_types ) + def _is_text_or_blob(self, field): + db_type = field.db_type(self.connection) + return db_type and db_type.lower().endswith(("blob", "text")) + def skip_default(self, field): + default_is_empty = self.effective_default(field) in ("", b"") + if default_is_empty and self._is_text_or_blob(field): + return True if not self._supports_limited_data_type_defaults: return self._is_limited_data_type(field) return False def skip_default_on_alter(self, field): + default_is_empty = self.effective_default(field) in ("", b"") + if default_is_empty and self._is_text_or_blob(field): + return True if self._is_limited_data_type(field) and not self.connection.mysql_is_mariadb: # MySQL doesn't support defaults for BLOB and TEXT in the # ALTER COLUMN statement.