我使用inspectdb创建了我的模型,当django生成以下内容时,它让我感到奇怪,因为只有一个这样的索引,但我让它成为
unique_together =(('p_id','v_id','sku',),('p_id','v_id','sku',))
现在我正在尝试将'sku2'添加到此索引中,并且'migrate'失败并显示以下内容:
File "/home/user/.pyenv/versions/2.7.11/envs/master2/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 347, in _delete_composed_index ", ".join(columns), ValueError: Found wrong number (2) of constraints for vendor_products(p_id, v_id, sku)
这是我的模特:
class Products(models.Model): p_id = models.OneToOneField(MasterProducts, models.DO_NOTHING, db_column='p_id', primary_key=True) v_id = models.ForeignKey('Sellers', models.DO_NOTHING, db_column='v_id') sku = models.TextField() sku2 = models.TextField(blank=True, null=True) class Meta: managed = True db_table = 'products' unique_together = (('p_id', 'v_id', 'sku',), ('p_id', 'v_id', 'sku',))
我尝试将unique_together更改为(('p_id','v_id','sku',),)和('p_id','v_id','sku'),结果相同.
我也尝试使用数据库手动删除唯一索引并使用django重新创建它,它仍然不会让我添加sku2.
为什么会发生这种情况,我该如何解决?