考虑下面的模型,我想索引的字段(序列,股吧)Django的:CREATE INDEX:非唯一,多列
class QuoteModel(models.Model):
quotedate = models.DateField()
high = models.FloatField() #(9,2) DEFAULT NULL,
low = models.FloatField() #(9,2) DEFAULT NULL,
close = models.FloatField() #(9,2) DEFAULT NULL,
closeadj = models.FloatField() #(9,2) DEFAULT NULL,
volume = models.IntegerField() #(9,2) DEFAULT NULL,
stock = models.IntegerField(db_index=True) #(9,2) DEFAULT NULL,
open = models.FloatField() #(9,2) DEFAULT NULL,
sequence = models.IntegerField() #(9,2) DEFAULT NULL,
该指数应该是不唯一的 - 在MySQL它应该是是这样的:
create index ndx_1 on model_quotemodel(sequence,stock);
唯一的解决办法Django的我所知道的是创建将由Django的在创建表执行的“SQL”的文件。所以,我创建了一个“stockmodel.sql”包含以下查询(同上:)
create index ndx_1 on model_quotemodel(sequence,stock);
有没有做这件事的任何“干净”的方式?
我不知道这答案真的解决了非主键组合键?似乎没有。 – 2011-03-16 00:05:59
这完全不是问题所在。需要非唯一的,非主要的组合键。 – Fydo 2013-10-30 23:48:21
我不认为上面的评论与当前的答案有关......从文档看来,'index_together' _does_提供了非唯一的,非主要的综合索引 – Anentropic 2017-07-24 12:48:53