Django迁移模型时报错:IndentationError: expected an indented block

在迁移模型Entry时,运行代码时

1
python manage.py makemigrations learning_logs

报错!

经官方文档解释:https://docs.djangoproject.com/en/1.11/ref/models/fields/#foreignkey发现`foreignkey`需要增加一个参数`on_delete`,于是将

1
topic = models.ForeignKey(Topic)

更改为:

1
topic = models.ForeignKey('Topic', on_delete=models.CASCADE)

运行成功!