MySQL Composite Indexing for Django

Posted my first Django snippet! This concerns a quick and dirty hack for getting composite indexing in MySQL. It’s also a simple example of how to use Django’s post_syncdb signal.

Django currently comes with a unique_together meta attribute you can use to specify unique combinations of fields. I think the backends create an index in the database from this. However, I couldn’t find anything for simply creating non-unique attributes, hence the hack you see in the snippet.

I don’t really have the patience to make it work fully for the other backends since I don’t use them currently (aside from SQLite3 for testing), but it’s GoodEnoughForMe.

Comments