Skip to content

Instantly share code, notes, and snippets.

@yuekui
Created May 21, 2021 20:59
Show Gist options
  • Save yuekui/f1277283b7470800c99a0d582817e8ed to your computer and use it in GitHub Desktop.
Save yuekui/f1277283b7470800c99a0d582817e8ed to your computer and use it in GitHub Desktop.
Monkey-patch Django mysql schema to skip setting default value when altering BLOB/TEXT fields
from django.db.backends.mysql import schema
class DatabaseSchemaEditor(schema.DatabaseSchemaEditor):
@property
def _supports_limited_data_type_defaults(self):
# 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
schema.DatabaseSchemaEditor = DatabaseSchemaEditor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment