在Django Admin中保存OnetoOneField,而null = True会出错

时间:2016-11-26 10:11:58

标签: django python-2.7 django-models

我的模型中有OnetoOnefield,设置为null = True且空白= True。一切都运行正常,但一旦我尝试从管理站点保存该模型的对象,我得到IntegrityError,说该字段不能为空。

我的模特是:

class Appointment(models.Model):
    doctor = models.OneToOneField(Doctor)
    clinic = models.OneToOneField(Clinic, null=True, blank=True)
    hospital = models.OneToOneField(Hospital, null=True, blank=True)

1 个答案:

答案 0 :(得分:0)

看看这个领域。

doctor = models.OneToOneField(Doctor)

class Appointment(models.Model):
    doctor = models.OneToOneField(Doctor)
    clinic = models.OneToOneField(Clinic, null=True, blank=True)
    hospital = models.OneToOneField(Hospital, null=True, blank=True)