Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Created special PostgreSQL text indexes when unique is True

Refs #19441.
  • Loading branch information...
commit c698c55966ed9179828857398d27bf69e64713a2 1 parent a890469
Claude Paroz authored January 07, 2013
2  django/db/backends/postgresql_psycopg2/creation.py
@@ -42,7 +42,7 @@ def sql_table_creation_suffix(self):
42 42
 
43 43
     def sql_indexes_for_field(self, model, f, style):
44 44
         output = []
45  
-        if f.db_index:
  45
+        if f.db_index or f.unique:
46 46
             qn = self.connection.ops.quote_name
47 47
             db_table = model._meta.db_table
48 48
             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
272 272
 This option is valid on all field types except :class:`ManyToManyField` and
273 273
 :class:`FileField`.
274 274
 
  275
+Note that when ``unique`` is ``True``, you don't need to specify
  276
+:attr:`~Field.db_index`, because ``unique`` implies the creation of an index.
  277
+
275 278
 ``unique_for_date``
276 279
 -------------------
277 280
 
2  tests/regressiontests/indexes/models.py
@@ -17,4 +17,4 @@ class Meta:
17 17
     class IndexedArticle(models.Model):
18 18
         headline = models.CharField(max_length=100, db_index=True)
19 19
         body = models.TextField(db_index=True)
20  
-        slug = models.CharField(max_length=40, unique=True, db_index=True)
  20
+        slug = models.CharField(max_length=40, unique=True)

0 notes on commit c698c55

Please sign in to comment.
Something went wrong with that request. Please try again.