How do I specify type of index in django? (btree vs hash, etc)

荒凉一梦 提交于 2019-12-22 10:56:18

问题


Like the title says, how do I specify the type of index I want on a field in a model in django.

class Person:
     ...
     age = models.IntegerField(db_index=True)

But now what? How do I make sure it is a btree index and not a hash. Or is this all done automatically for us and there is some large table that django uses for choosing the "optimal index type"


回答1:


Django defaults to creating btree indexes whenever you specify index=True:

https://docs.djangoproject.com/en/1.11/ref/models/indexes/

I note you're using MySQL; but if you're using PostgreSQL, you can specify certain other index types on certain types of fields:

https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/

This answer gives information on how you can override the btree default in MySQL, should you ever need to:

https://stackoverflow.com/a/3288059/1394697



来源:https://stackoverflow.com/questions/45125741/how-do-i-specify-type-of-index-in-django-btree-vs-hash-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!