我想为表a
创建两个引用相同表b
的外键。请帮助。
我正在使用Django 2.1.7:
class Subject_matter (models.Model):
subject_matter_id = models.AutoField(primary_key=True)
name_subject_matter = models.CharField(max_length=255)
universitycareer = models.ForeignKey(Item_category, on_delete = models.CASCADE)
class Pre_requirements (models.Model):
pre_requirements_id = models.AutoField(primary_key=True)
subject_matter_id_1 = models.ForeignKey(Subject_matter, on_delete=models.CASCADE, null=True, related_name='subject_matter_id_1')
subject_matter_requeriment_id = models.ForeignKey(Subject_matter, on_delete=models.CASCADE, null=True, related_name='subject_matter_requeriment_id')
终端中的消息错误:
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')