#24082: Unique=True on TextField or CharField should not create an index
-------------------------------------+-------------------------------------
     Reporter:  djbug                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.7
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by marfire):

 In my opinion it would be better to not have `unique=True` imply
 `db_index=True`. How the database enforces the constraint seems more like
 an implementation detail than something Django should guarantee.

 However, this is the
 [https://docs.djangoproject.com/en/1.7/ref/models/fields/#unique currently
 documented behavior] ("Note that when `unique` is `True` you don’t need to
 specify `db_index`, because `unique` implies the creation of an index"),
 so there would be a backwards-compatibility problem in changing it.

 The fact that you can't prevent the creation of the extra index with an
 explicit `db_index=False` does feel like a bug, though, and something that
 could be fixed without a deprecation cycle.

 As for the suggestion to use a single `text_pattern_ops` unique index to
 serve double duty, the [http://www.postgresql.org/docs/9.3/static/indexes-
 opclass.html PostgreSQL documentation] makes it clear that that will not
 suffice to support all of Django's lookup types: "Note that you should
 also create an index with the default operator class if you want queries
 involving ordinary <, <=, >, or >= comparisons to use an index. Such
 queries cannot use the xxx_pattern_ops operator classes."

--
Ticket URL: <https://code.djangoproject.com/ticket/24082#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/063.d50fc6c7d17bcd61b4bf45b9a603903a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to