mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #30591 -- Fixed introspection of check and unique column constraints on MariaDB.
Unnamed unique and check columns constraints have the same name as a column. Ensure uniqueness by using custom names. Thanks Adnan Umer for the report.
This commit is contained in:
@@ -207,6 +207,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
constraints[constraint]['unique'] = True
|
||||
# Add check constraints.
|
||||
if self.connection.features.can_introspect_check_constraints:
|
||||
unnamed_constraints_index = 0
|
||||
columns = {info.name for info in self.get_table_description(cursor, table_name)}
|
||||
type_query = """
|
||||
SELECT c.constraint_name, c.check_clause
|
||||
@@ -217,8 +218,15 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
"""
|
||||
cursor.execute(type_query, [table_name])
|
||||
for constraint, check_clause in cursor.fetchall():
|
||||
constraint_columns = self._parse_constraint_columns(check_clause, columns)
|
||||
# Ensure uniqueness of unnamed constraints. Unnamed unique
|
||||
# and check columns constraints have the same name as
|
||||
# a column.
|
||||
if set(constraint_columns) == {constraint}:
|
||||
unnamed_constraints_index += 1
|
||||
constraint = '__unnamed_constraint_%s__' % unnamed_constraints_index
|
||||
constraints[constraint] = {
|
||||
'columns': self._parse_constraint_columns(check_clause, columns),
|
||||
'columns': constraint_columns,
|
||||
'primary_key': False,
|
||||
'unique': False,
|
||||
'index': False,
|
||||
|
||||
Reference in New Issue
Block a user