Bob*_*oid -1 python django django-models django-admin
这是我的Django模型
class author(models.Model):
name = models.CharField('name',max_length=140)
datamode = models.CharField(max_length=1, default='A', choices=DATAMODE_CHOICE)
def __str__(self):
return '%s' % (self.name)
Run Code Online (Sandbox Code Playgroud)
虽然我author在另一个类中使用此类作为外键,如下所示:
class books(models.Model):
NEW_FLAG=(('N','New'),('O','Old'))
name = models.CharField('name',max_length=140)
author = models.ForeignKey(author, blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
当我在管理员中输入新书详细信息时,它显示:
IntegrityError: Column 'author_id' cannot be null.
Run Code Online (Sandbox Code Playgroud)