Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.5.x] Created special PostgreSQL text indexes when unique is True

Refs #19441.
Backport of c698c55 from master.
  • Loading branch information...
commit 012229914cb1391ee4fcb6c183a341a6491cd377 1 parent 7ca9b71
@claudep claudep authored
2  django/db/backends/postgresql_psycopg2/
@@ -42,7 +42,7 @@ def sql_table_creation_suffix(self):
def sql_indexes_for_field(self, model, f, style):
output = []
- if f.db_index:
+ if f.db_index or f.unique:
qn = self.connection.ops.quote_name
db_table = model._meta.db_table
tablespace = f.db_tablespace or model._meta.db_tablespace
3  docs/ref/models/fields.txt
@@ -272,6 +272,9 @@ field, a :exc:`django.db.IntegrityError` will be raised by the model's
This option is valid on all field types except :class:`ManyToManyField` and
+Note that when ``unique`` is ``True``, you don't need to specify
+:attr:`~Field.db_index`, because ``unique`` implies the creation of an index.
2  tests/regressiontests/indexes/
@@ -17,4 +17,4 @@ class Meta:
class IndexedArticle(models.Model):
headline = models.CharField(max_length=100, db_index=True)
body = models.TextField(db_index=True)
- slug = models.CharField(max_length=40, unique=True, db_index=True)
+ slug = models.CharField(max_length=40, unique=True)
Please sign in to comment.
Something went wrong with that request. Please try again.