Python django 1.6中的部分索引
我有下面的模型Python django 1.6中的部分索引,python,django,Python,Django,我有下面的模型 class Payment(AbstractBaseModel): sales_order = models.ForeignKey( 'salesorders.SalesOrder', verbose_name=_('Sales Order'), unique=True) invoice = models.ForeignKey( 'accounting.Invoice', help_
class Payment(AbstractBaseModel):
sales_order = models.ForeignKey(
'salesorders.SalesOrder',
verbose_name=_('Sales Order'),
unique=True)
invoice = models.ForeignKey(
'accounting.Invoice',
help_text=_('invoice to which the payment belongs to'),
verbose_name=_('invoice'),
null=True,blank=True
)
两者在一起是唯一的,并且一起索引
因此,我通过添加如下类Meta
选项重写了上述模型
class Payment(AbstractBaseModel):
sales_order = models.ForeignKey(
'salesorders.SalesOrder',
verbose_name=_('Sales Order'),
unique=True)
invoice = models.ForeignKey(
'accounting.Invoice',
help_text=_('invoice to which the payment belongs to'),
verbose_name=_('invoice'),
null=True,blank=True
)
class Meta:
app_label = 'payments'
unique_together = ('sales_order','invoice')
index_together = [['sales_order','invoice']]
这是不符合逻辑的,因为这些字段实际上是相互之间的部分索引,所以我的django版本是1.6,在这种情况下,我应该怎么做?您确实需要升级到django的受支持版本,因为您缺少了这些内容 在1.7中,部分索引通过迁移得到支持,迁移本身就是从South项目中吸收的一项功能 您可以(也应该)使用South-create空迁移,并使用创建部分索引 这也是django内置迁移提供的解决方案,但它们在命令周围有一个不同的包装器;使用
RunSQL