Python Django:如何选择索引类型? [英] Python Django: how to select the index type?

查看:43
本文介绍了Python Django:如何选择索引类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As stated in https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.Field.db_index, you can add indexes to your table using db_index=True. But how do you force hash vs btree indexes?

推荐答案

Django尚未通过模型实现特定的索引类型选择.

Django has no implemented particular index type selection through models.

解决方法是创建空迁移并在迁移中编写SQL语句以保持一致性

Workaround would be to create empty migration and write SQL statement in your migration for consistency

https://docs.djangoproject.com/en/1.10/howto/writing-migrations/

manage.py makemigrations --empty app

在迁移操作过程中,

migrations.RunSQL('Query to add index')

RunSQL文档

这篇关于Python Django:如何选择索引类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆