使用应用程序创建一个Django项目(将其添加到INSTALLED_APPS!)使用以下models.py
from django.db import models
class BaseTransaction(models.Model):
pass
class SubscriptionTransaction(BaseTransaction):
class Meta:
index_together = ["id", "canceled"]
canceled = models.BooleanField()然后事情是这样的:
$ python3 manage.py makemigrations
SystemCheckError: System check identified some issues:
ERRORS:
testprj.SubscriptionTransaction: (models.E016) 'index_together' refers to field 'id' which is not local to model 'SubscriptionTransaction'.
HINT: This issue may be caused by multi-table inheritance.请解释这个错误的原因(这里没有多表继承),以及如何使我的代码工作。
这个问题发生在Django 1.10.3和Python 3.5.3和Python 2.7.13上。是Django的bug吗?变通方法是什么?
发布于 2017-07-24 05:59:54
您会收到此错误,因为您正在使用的id在其他表中,这可能会产生许多问题。
但是如果你不需要BaseTransaction表,你可以把它标记为抽象的,然后你就可以完美地使用你的index_together了。
class BaseTransaction(models.Model):
class Meta:
abstract = Truehttps://stackoverflow.com/questions/45269980
复制相似问题