【发布时间】:2010-12-07 09:13:22
【问题描述】:
给定以下模型,我想索引字段(序列,股票)
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 解决方法是创建一个“sql”文件,该文件将由 django 在创建表时执行。因此,我创建了一个包含以下查询的“stockmodel.sql”(与上面相同:)
create index ndx_1 on model_quotemodel(sequence,stock);
有没有“更清洁”的方法?
【问题讨论】: