我有这个型号:
#models.py
class Enrollment(models.Model):
student = models.ForeignKey(User, on_delete=models.PROTECT)
curriculum = models.ForeignKey(Curriculum, on_delete=models.PROTECT)
enrolment_date = models.DateTimeField(null=True,blank=True,auto_now_add=True)
payed_amount = models.PositiveIntegerField(null=True,blank=True)
is_complete_paid = models.BooleanField(null=True,blank=True,default=False)
class Meta:
unique_together = (("student", "curriculum"),)
当我想用以下代码在我的views.py
中创建新注册时:
我有个错误:
UNIQUE constraint failed: lms_enrollment.student_id, lms_enrollment.curriculum_id
为什么会发生这个错误?是否可以解释此错误的原因并介绍一些相关文档?在
在Meta.unique一起这意味着数据库中的两个字段不能超过1
^{pr2}$相关问题 更多 >
编程相关推荐