gpt4 book ai didi

python Django : how to select the index type?

转载 作者:行者123 更新时间:2023-11-28 17:20:15 27 4
gpt4 key购买 nike

https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.Field.db_index 中所述,您可以使用 db_index=True 将索引添加到表中。但是你如何强制哈希索引与 btree 索引?

最佳答案

自从提出问题以来,情况发生了很大变化。现在可以通过模型的元类在模型层中定义索引(至少从 django 1.11 开始): https://docs.djangoproject.com/en/dev/ref/contrib/postgres/indexes/

例如:

from django.contrib.postgres.indexes import HashIndex
from django.db import models


class User(models.Model):
name = models.CharField(max_length=100)

class Meta:
indexes = (HashIndex(fields=('name',)),)

关于 python Django : how to select the index type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41955346/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com