我有一个名为Lecture的模型,该模型对我的Courses模型具有外键。当我尝试添加一个讲座时,一切正常,但是当我尝试删除一个讲座时,很有可能会出现50%的错误。我不知道为什么可以删除某些内容,但是对于某些内容,我会收到以下错误消息:
这也是我的演讲模型:
class Lecture(models.Model):
LECTURE_CHOICES = (
('Courses', 'Courses'),
('Seminars', 'Seminars'),
)
course = models.ForeignKey('Course', on_delete=models.CASCADE, null=True, related_name='lectures', )
lecture_category = models.CharField(max_length=10, choices=LECTURE_CHOICES, default='Courses', )
lecture_title = models.CharField(max_length=100, blank=True)
content = models.TextField(blank=True)
def __str__(self):
return str(self.lecture_title)
class Course(models.Model):
study_programme = models.ForeignKey('StudyProgramme', on_delete=models.CASCADE, null=True, blank=True)
name = models.CharField(max_length=50, unique=True)
ects = models.PositiveSmallIntegerField(validators=[MaxValueValidator(99)])
description = models.TextField()
year = models.PositiveSmallIntegerField(validators=[MaxValueValidator(99)])
semester = models.IntegerField(choices=((1, "1"),
(2, "2"),
), default=1)
teacher1 = models.ForeignKey('TeacherData', on_delete=models.CASCADE, null=True, blank=True,
verbose_name="Course Teacher", related_name='%(class)s_course_teacher')
teacher2 = models.ForeignKey('TeacherData', on_delete=models.CASCADE, null=True, blank=True,
verbose_name="Seminar Teacher", related_name='%(class)s_seminar_teacher')
student = models.ManyToManyField('StudentData')
slug = models.SlugField(max_length=150, unique=True)
allow_upload = models.BooleanField(default=False)
def __str__(self):
return self.name