我已经达到了Mozilla Django教程的第4章,但后来我遇到了这个错误.我按照它说的所有内容进行了操作,但是当我尝试从管理面板打开BookInstance模型时,它给了我这个错误:
/ admin/catalog/bookinstance /'NoneType'对象中的AttributeError没有属性'id'
这是我的代码,models.py(我突出显示了发生错误的部分):
from django.db import models
from django.core.urlresolvers import reverse
class Book(models.Model):
"""
Model representing a book (but not a specific copy of a book).
"""
title = models.CharField(max_length=200)
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
# Foreign Key used because book can only have one author, but authors can have multiple books
# Author as a string rather than object because it hasn't been declared yet in file.
summary = models.TextField(max_length=1000, help_text="Enter a …Run Code Online (Sandbox Code Playgroud)