summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/schema.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-03-03 16:50:34 +0100
committerTim Graham <timograham@gmail.com>2017-03-03 10:50:34 -0500
commit6b47431aaf5222b687791f92f352413a16fc62cd (patch)
tree65597734f839e03e1adbc56aa1aa9def56296817 /django/db/backends/postgresql/schema.py
parentd82ee32aac323b7260cc95278c69b81d98dbd00a (diff)
downloaddjango-6b47431aaf5222b687791f92f352413a16fc62cd.tar.gz
Refs #27860 -- Simplified deleting indexes on PostgreSQL using "IF EXISTS".
Diffstat (limited to 'django/db/backends/postgresql/schema.py')
-rw-r--r--django/db/backends/postgresql/schema.py6
1 files changed, 2 insertions, 4 deletions
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index 9cedc763bd..f6be40f846 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -14,6 +14,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
sql_create_index = "CREATE INDEX %(name)s ON %(table)s%(using)s (%(columns)s)%(extra)s"
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"
+ sql_delete_index = "DROP INDEX IF EXISTS %(name)s"
# Setting the constraint to IMMEDIATE runs any deferred checks to allow
# dropping it in the same transaction.
@@ -117,7 +118,4 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# Removed an index? Drop any PostgreSQL-specific indexes.
if old_field.unique and not (new_field.db_index or new_field.unique):
index_to_remove = self._create_index_name(model, [old_field.column], suffix='_like')
- index_names = self._constraint_names(model, [old_field.column], index=True)
- for index_name in index_names:
- if index_name == index_to_remove:
- self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_name))
+ self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_to_remove))