Когда я запускаю следующую команду:
python manage.py makemigrations
У меня появляется эта ошибка:
File "/home/user/project/myvirt/forum/boards/models.py", line 9, in <module>
class Topic(models.Model):
File "/home/user/project/myvirt/forum/boards/models.py", line 12, in Topic
board = models.ForeignKey(Board, related_name='topics', on_delete='cascade')
File "/usr/local/lib/python3.7/dist-packages/django/db/models/fields/related.py", line 801, in __init__
raise TypeError('on_delete must be callable.')
TypeError: on_delete must be callable.
Мой контент models.py:
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Board(models.Model):
name = models.CharField(max_length=30, unique=True)
description = models.CharField(max_length=100)
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', on_delete='cascade')
creator = models.ForeignKey(User, related_name='topics', on_delete='cascade')
class Post(models.Model):
message = models.TextField(max_length=4000)
topic = models.CharField(Topic, related_name='posts', on_delete='cascade')
created_by = models.CharField(User, related_name='posts', on_delete='cascade')
created_at = models.DateTimeField(auto_now_add=True)
updated_by = models.CharField(User, related_name='posts', on_delete='cascade')
updated_at = models.DateTimeField(null=True)
This является упражнением в примере форума и, похоже, проблема с on_delete='cascade'
.
Обновление:
Я использую Django версия 3.