# 出版社 class Publisher(models.Model): # 自增、主键 id id = models.AutoField(primary_key=True) # varchar(32)、不为空、唯一索引 name = models.CharField(max_length=32, null=False, unique=True) # 书 class Booker(models.Model): id = models.AutoField(primary_key=True) title = models.CharField(max_length=64, null=False, unique=True) publisher = models.ForeignKey(to="Publisher")
报错
解决方案
publisher = models.ForeignKey(to="Publisher", on_delete=models.CASCADE)
原文:https://www.cnblogs.com/wt7018/p/11234424.html