Ticket #30750: 30750.diff

File 30750.diff, 4.8 KB (added by Mariusz Felisiak, 5 years ago)

patch

  • django/db/backends/mysql/base.py

    diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
    index febc246e09..d60ff7937d 100644
    a b class CursorWrapper:  
    6161    codes_for_integrityerror = (
    6262        1048,  # Column cannot be null
    6363        1690,  # BIGINT UNSIGNED value is out of range
     64        3819,  # CHECK constraint is violated
    6465        4025,  # CHECK constraint failed
    6566    )
    6667
  • django/db/backends/mysql/features.py

    diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py
    index 229e26a750..5800ad6c95 100644
    a b class DatabaseFeatures(BaseDatabaseFeatures):  
    8989
    9090    @cached_property
    9191    def supports_column_check_constraints(self):
    92         return self.connection.mysql_is_mariadb and self.connection.mysql_version >= (10, 2, 1)
     92        if self.connection.mysql_is_mariadb:
     93            return self.connection.mysql_version >= (10, 2, 1)
     94        return self.connection.mysql_version >= (8, 0, 16)
    9395
    9496    supports_table_check_constraints = property(operator.attrgetter('supports_column_check_constraints'))
    9597
    class DatabaseFeatures(BaseDatabaseFeatures):  
    99101            version = self.connection.mysql_version
    100102            if (version >= (10, 2, 22) and version < (10, 3)) or version >= (10, 3, 10):
    101103                return True
    102         return False
     104        return self.connection.mysql_version >= (8, 0, 16)
    103105
    104106    @cached_property
    105107    def has_select_for_update_skip_locked(self):
  • django/db/backends/mysql/introspection.py

    diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
    index 82637d15fb..a014b87916 100644
    a b class DatabaseIntrospection(BaseDatabaseIntrospection):  
    209209        if self.connection.features.can_introspect_check_constraints:
    210210            unnamed_constraints_index = 0
    211211            columns = {info.name for info in self.get_table_description(cursor, table_name)}
    212             type_query = """
    213                 SELECT c.constraint_name, c.check_clause
    214                 FROM information_schema.check_constraints AS c
    215                 WHERE
    216                     c.constraint_schema = DATABASE() AND
    217                     c.table_name = %s
    218             """
     212            if self.connection.mysql_is_mariadb:
     213                type_query = """
     214                    SELECT c.constraint_name, c.check_clause
     215                    FROM information_schema.check_constraints AS c
     216                    WHERE
     217                        c.constraint_schema = DATABASE() AND
     218                        c.table_name = %s
     219                """
     220            else:
     221                type_query = """
     222                    SELECT cc.constraint_name, cc.check_clause
     223                    FROM
     224                        information_schema.check_constraints AS cc,
     225                        information_schema.table_constraints AS tc
     226                    WHERE
     227                        cc.constraint_schema = DATABASE() AND
     228                        tc.table_schema = cc.constraint_schema AND
     229                        cc.constraint_name = tc.constraint_name AND
     230                        tc.constraint_type = 'CHECK' AND
     231                        tc.table_name = %s
     232                """
    219233            cursor.execute(type_query, [table_name])
    220234            for constraint, check_clause in cursor.fetchall():
    221235                constraint_columns = self._parse_constraint_columns(check_clause, columns)
  • django/db/backends/mysql/schema.py

    diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py
    index d138606791..d379965c27 100644
    a b class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):  
    2828    sql_delete_pk = "ALTER TABLE %(table)s DROP PRIMARY KEY"
    2929
    3030    sql_create_index = 'CREATE INDEX %(name)s ON %(table)s (%(columns)s)%(extra)s'
    31     # The name of the column check constraint is the same as the field name on
    32     # MariaDB. Adding IF EXISTS clause prevents migrations crash. Constraint is
    33     # removed during a "MODIFY" column statement.
    34     sql_delete_check = 'ALTER TABLE %(table)s DROP CONSTRAINT IF EXISTS %(name)s'
     31
     32    @property
     33    def sql_delete_check(self):
     34        if self.connection.mysql_is_mariadb:
     35            # The name of the column check constraint is the same as the field
     36            # name on MariaDB. Adding IF EXISTS clause prevents migrations
     37            # crash. Constraint is removed during a "MODIFY" column statement.
     38            return 'ALTER TABLE %(table)s DROP CONSTRAINT IF EXISTS %(name)s'
     39        return 'ALTER TABLE %(table)s DROP CHECK %(name)s'
    3540
    3641    def quote_value(self, value):
    3742        self.connection.ensure_connection()
Back to Top