summaryrefslogtreecommitdiff
path: root/django/db/backends/postgresql/schema.py
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-05-24 07:25:59 +0200
committerGitHub <noreply@github.com>2017-05-24 07:25:59 +0200
commit91b2bc3e70be2632baad86488fb03cf02848b5b6 (patch)
treeba7ea6af20be180fc0442684580c46defa86eedd /django/db/backends/postgresql/schema.py
parent538bf43458a147b7edeb7118c9f325c3f59ff6fb (diff)
downloaddjango-91b2bc3e70be2632baad86488fb03cf02848b5b6.tar.gz
Fixed #27860 -- Dropped varchar_pattern_ops/text_pattern_ops index before altering char/text field in PostgreSQL.
Thanks Tim Graham for the review.
Diffstat (limited to 'django/db/backends/postgresql/schema.py')
-rw-r--r--django/db/backends/postgresql/schema.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index f6be40f846..8d4db4ea1c 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -104,6 +104,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
+ # Drop indexes on varchar/text columns that are changing to a different
+ # type.
+ if (old_field.db_index or old_field.unique) and (
+ (old_type.startswith('varchar') and not new_type.startswith('varchar')) or
+ (old_type.startswith('text') and not new_type.startswith('text'))
+ ):
+ index_name = self._create_index_name(model, [old_field.column], suffix='_like')
+ self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_name))
+
super()._alter_field(
model, old_field, new_field, old_type, new_type, old_db_params,
new_db_params, strict,