summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/schema.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-12-17 15:06:47 -0500
committerSimon Charette <charette.s@gmail.com>2016-12-24 13:53:11 -0500
commitcd7efa20338cb6f3ede4780e00590c0a6dd48ca2 (patch)
treef38adc44e59a35313c18e5f9cb1cb21467c900f8 /django/db/backends/postgresql/schema.py
parenta4cac1720034920351291359d0bb2177d8c8a4d5 (diff)
downloaddjango-cd7efa20338cb6f3ede4780e00590c0a6dd48ca2.tar.gz
Fixed #25492 -- Checked deferred foreign key constraints before dropping them.
This allows running foreign key data and schema altering operations in the same migration on PostgreSQL. Thanks Tim for review.
Diffstat (limited to 'django/db/backends/postgresql/schema.py')
-rw-r--r--django/db/backends/postgresql/schema.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index 1afb85d468..bffa8bd45b 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -15,6 +15,10 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_create_varchar_index = "CREATE INDEX %(name)s ON %(table)s (%(columns)s varchar_pattern_ops)%(extra)s"
sql_create_text_index = "CREATE INDEX %(name)s ON %(table)s (%(columns)s text_pattern_ops)%(extra)s"
+ # Setting the constraint to IMMEDIATE runs any deferred checks to allow
+ # dropping it in the same transaction.
+ sql_delete_fk = "SET CONSTRAINTS %(name)s IMMEDIATE; ALTER TABLE %(table)s DROP CONSTRAINT %(name)s"
+
def quote_value(self, value):
return psycopg2.extensions.adapt(value)