Skip to content

Commit

Permalink
[1.5.x] Created special PostgreSQL text indexes when unique is True
Browse files Browse the repository at this point in the history
Refs #19441.
Backport of c698c55 from master.
  • Loading branch information
claudep committed Jan 7, 2013
1 parent 7ca9b71 commit 0122299
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion django/db/backends/postgresql_psycopg2/creation.py
Expand Up @@ -42,7 +42,7 @@ def sql_table_creation_suffix(self):


def sql_indexes_for_field(self, model, f, style): def sql_indexes_for_field(self, model, f, style):
output = [] output = []
if f.db_index: if f.db_index or f.unique:
qn = self.connection.ops.quote_name qn = self.connection.ops.quote_name
db_table = model._meta.db_table db_table = model._meta.db_table
tablespace = f.db_tablespace or model._meta.db_tablespace tablespace = f.db_tablespace or model._meta.db_tablespace
Expand Down
3 changes: 3 additions & 0 deletions docs/ref/models/fields.txt
Expand Up @@ -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 This option is valid on all field types except :class:`ManyToManyField` and
:class:`FileField`. :class:`FileField`.


Note that when ``unique`` is ``True``, you don't need to specify
:attr:`~Field.db_index`, because ``unique`` implies the creation of an index.

``unique_for_date`` ``unique_for_date``
------------------- -------------------


Expand Down
2 changes: 1 addition & 1 deletion tests/regressiontests/indexes/models.py
Expand Up @@ -17,4 +17,4 @@ class Meta:
class IndexedArticle(models.Model): class IndexedArticle(models.Model):
headline = models.CharField(max_length=100, db_index=True) headline = models.CharField(max_length=100, db_index=True)
body = models.TextField(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)

0 comments on commit 0122299

Please sign in to comment.