根据下面的模型,我想对字段(序列、股票)进行索引
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将在创建表时执行该文件.因此,我创建了一个包含以下查询的"stock model.sql"(同上:)
create index ndx_1 on model_quotemodel(sequence,stock);
有没有什么"干净"的方法呢?