1
0
mirror of https://github.com/django/django.git synced 2025-10-26 23:26:08 +00:00

Fixed #26034 -- Fixed incorrect index handling on PostgreSQL on Char/TextField with unique=True and db_index=True.

Thanks Simon Charette for review.
This commit is contained in:
Tim Graham
2016-01-07 20:06:58 -05:00
parent 54d3ba8406
commit 56aaae58a7
4 changed files with 72 additions and 2 deletions

View File

@@ -111,13 +111,13 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
new_db_params, strict,
)
# Added an index? Create any PostgreSQL-specific indexes.
if ((not old_field.db_index and new_field.db_index) or (not old_field.unique and new_field.unique)):
if not old_field.db_index and not old_field.unique and (new_field.db_index or new_field.unique):
like_index_statement = self._create_like_index_sql(model, new_field)
if like_index_statement is not None:
self.execute(like_index_statement)
# Removed an index? Drop any PostgreSQL-specific indexes.
if ((not new_field.db_index and old_field.db_index) or (not new_field.unique and old_field.unique)):
if (old_field.db_index or 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: