如果我将以下类添加到我的模型中,则一切都可以正常进行迁移。
class BeursCheck(models.Model):
order = models.IntegerField(default=None)
painting = models.ForeignKey(Painting, related_name='beursCheck',primary_key=True)
但是,如果我添加此字段..
mturk_assignment = models.ForeignKey(
'mturk.MtAssignment', null=True, blank=True,
related_name='+', on_delete=models.SET_NULL, unique=True
)
失败并显示错误
django.db.utils.ProgrammingError: there is no unique constraint matching given keys for referenced table "mturk_mtassignment"
此字段与MtAssignemnt相关,具有唯一键。 This related answered even says so.
class MtAssignment(MtModelBase):
id = models.CharField(max_length=128, primary_key=True)
答案 0 :(得分:0)
尝试更改为:
from mturk.models import MtAssigmnet
mturk_assignment = models.ForeignKey(
MtAssignment, null=True, blank=True,
related_name='+', on_delete=models.SET_NULL
)