mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #31735 -- Fixed migrations crash on namespaced inline FK addition on PostgreSQL.
The namespace of the constraint must be included when making the
constraint immediate.
Regression in 22ce5d0031.
Thanks Rodrigo Estevao for the report.
This commit is contained in:
committed by
Mariusz Felisiak
parent
6f3e3e87ab
commit
2e8941b6f9
@@ -466,8 +466,10 @@ class BaseDatabaseSchemaEditor:
|
||||
if self.sql_create_column_inline_fk:
|
||||
to_table = field.remote_field.model._meta.db_table
|
||||
to_column = field.remote_field.model._meta.get_field(field.remote_field.field_name).column
|
||||
namespace, _ = split_identifier(model._meta.db_table)
|
||||
definition += " " + self.sql_create_column_inline_fk % {
|
||||
'name': self._fk_constraint_name(model, field, constraint_suffix),
|
||||
'namespace': '%s.' % self.quote_name(namespace) if namespace else '',
|
||||
'column': self.quote_name(field.column),
|
||||
'to_table': self.quote_name(to_table),
|
||||
'to_column': self.quote_name(to_column),
|
||||
|
||||
@@ -27,7 +27,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
# transaction.
|
||||
sql_create_column_inline_fk = (
|
||||
'CONSTRAINT %(name)s REFERENCES %(to_table)s(%(to_column)s)%(deferrable)s'
|
||||
'; SET CONSTRAINTS %(name)s IMMEDIATE'
|
||||
'; SET CONSTRAINTS %(namespace)s%(name)s IMMEDIATE'
|
||||
)
|
||||
# Setting the constraint to IMMEDIATE runs any deferred checks to allow
|
||||
# dropping it in the same transaction.
|
||||
|
||||
Reference in New Issue
Block a user