Django: create Index: non-unique, multiple column
There is a ticket for this feature. Take a look http://code.djangoproject.com/ticket/5805
You may apply the patch from this ticket yourself.
UPDATE
It's now in Django: https://docs.djangoproject.com/en/1.5/ref/models/options/#django.db.models.Options.index_together
To follow on from the accepted answer, if you are using South, you can easily add a composite key as follows:
manage.py schemamigration your_app_name name_for_migration --add-index ModelName.first_field_in_index
You can then edit the generated migration file to add the additional fields into the one index (you'll see it's just a list of field names that's needed).
Don't forget to update the reverse migration as well as the forward one.
As of Django 1.5, you can use the Meta.index_together
option:
class QuoteModel(models.Model):
# ... fields ...
class Meta:
index_together = [
("sequence", "stock"),
]
(note: the original answer from 2009 said it was not possible to index multiple fields; it has since been replaced)
It is index_together in django 1.5
See here https://docs.djangoproject.com/en/dev/ref/models/options/#index-together