小编Ade*_*ina的帖子

类型错误:__init__() 缺少 1 个必需的位置参数:'on_delete'

我正在尝试运行我的代码,但收到此错误:

  File "C:\Users\JOSHUA\Documents\ypgforum\myproject\boards\models.py", line 13, in <module>
    class Topic(models.Model):
  File "C:\Users\JOSHUA\Documents\ypgforum\myproject\boards\models.py", line 16, in Topic
    board = models.ForeignKey(Board, related_name='topics')
TypeError: __init__() missing 1 required positional argument: 'on_delete'
Run Code Online (Sandbox Code Playgroud)

这是它指向的 models.py:

class Topic(models.Model):
    subject = models.CharField(max_length=255)
    last_updated = models.DateTimeField(auto_now_add=True)
    board = models.ForeignKey(Board, related_name='topics')
    starter = models.ForeignKey(User, related_name='topics')
    last_updated = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

python django django-models

-1
推荐指数
1
解决办法
8060
查看次数

标签 统计

django ×1

django-models ×1

python ×1