[4.1.x] Refs #23740 -- Added BaseDatabaseSchemaEditor._unique_constraint_name().

Backport of 115a978fce from main
This commit is contained in:
David Wobrock 2022-05-26 07:26:33 +02:00 committed by Mariusz Felisiak
parent 44e754fc83
commit 176d5ec242
1 changed files with 12 additions and 4 deletions

View File

@ -1560,16 +1560,13 @@ class BaseDatabaseSchemaEditor:
): ):
return None return None
def create_unique_name(*args, **kwargs):
return self.quote_name(self._create_index_name(*args, **kwargs))
compiler = Query(model, alias_cols=False).get_compiler( compiler = Query(model, alias_cols=False).get_compiler(
connection=self.connection connection=self.connection
) )
table = model._meta.db_table table = model._meta.db_table
columns = [field.column for field in fields] columns = [field.column for field in fields]
if name is None: if name is None:
name = IndexName(table, columns, "_uniq", create_unique_name) name = self._unique_constraint_name(table, columns, quote=True)
else: else:
name = self.quote_name(name) name = self.quote_name(name)
if condition or include or opclasses or expressions: if condition or include or opclasses or expressions:
@ -1592,6 +1589,17 @@ class BaseDatabaseSchemaEditor:
include=self._index_include_sql(model, include), include=self._index_include_sql(model, include),
) )
def _unique_constraint_name(self, table, columns, quote=True):
if quote:
def create_unique_name(*args, **kwargs):
return self.quote_name(self._create_index_name(*args, **kwargs))
else:
create_unique_name = self._create_index_name
return IndexName(table, columns, "_uniq", create_unique_name)
def _delete_unique_sql( def _delete_unique_sql(
self, self,
model, model,