考慮下面的模型,我想索引的字段(序列,股吧)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