就像标题所说,如何在 django 模型中的字段上指定我想要的索引类型?
class Person:
...
age = models.IntegerField(db_index=True)
现在怎么办?我如何确保它是一个btree index
而不是一个hash index
?这个过程是否通过使用 Django 用来在内部确定最佳索引类型的大型表来自动化?理想情况下,我想要一种手动方式来更改这些设置。
Django默认创建btree
每当您指定时索引index=True
:
https://docs.djangoproject.com/en/1.11/ref/models/indexes/ https://docs.djangoproject.com/en/1.11/ref/models/indexes/
我注意到你正在使用 MySQL;但如果您使用 PostgreSQL,则可以在某些类型的字段上指定某些其他索引类型:
https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/ https://docs.djangoproject.com/en/1.11/ref/contrib/postgres/indexes/
该答案提供了有关如何覆盖的信息btree
MySQL 中的默认值,如果您需要:
https://stackoverflow.com/a/3288059/1394697 https://stackoverflow.com/a/3288059/1394697
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)