class Entry(models.Model):
    
    #引用数据库中的另一条记录
    topic = models.ForeignKey(Topic)
    text = models.TextField()
    date_added = models.DateTimeField(auto_now_add = True)
    class Mate:
        verbose_name_plural = 'entries'
        def __str__(self):
            #返回模型的字符串表示
            return self.text[:50]+"..."上面是最初的代码,指定一个外键时 ,进行迁移时报错:TypeError: ForeignKey.__init__() missing 1 required positional argument: 'on_delete'
即 外键 丢失了一个需要的位置参数“on_delete”
解决办法: topic = models.ForeignKey(Topic,on_delete=models.CASCADE)
具体原因请查看下面的博客:
(100条消息) model.ForeignKey() TypeError: __init__() missing 1 required positional argument: 'on_delete'_再努力一点吧-CSDN博客 https://blog.csdn.net/weixin_43424969/article/details/84478669
https://blog.csdn.net/weixin_43424969/article/details/84478669









