Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django 1.6中的部分索引_Python_Django - Fatal编程技术网

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