擅长:python、mysql、java
<p>我已经测试了你的代码。我认为你有一个过时的sqlite数据库</p>
<p>请尝试以下内容</p>
<ul>
<li>删除sqlite数据库</li>
<li>通过<code>python manage.py makemigrations</code>重新生成迁移</li>
<li>通过<code>python manage.py migrate</code>更新数据库</li>
</ul>
<p>代码的某些部分需要修复</p>
<p>首先,图书模型没有名称字段</p>
<p>所以,这条线需要修好</p>
<blockquote>
<blockquote>
<p>book = Book.objects.create(name=data['title'], author=author, user=user)</p>
</blockquote>
</blockquote>
<p>这将是</p>
<blockquote>
<blockquote>
<p>book = Book.objects.create(title=data['title'], author=author)</p>
</blockquote>
</blockquote>
<p>第二,不能像这样分配多对多字段<code>user</code></p>
<blockquote>
<blockquote>
<p>book = Book.objects.create(name=data['title'], author=author, user=user)</p>
</blockquote>
</blockquote>
<p>正确的格式是</p>
<blockquote>
<blockquote>
<p>book = Book.objects.create(title=data['title'], author=author)</p>
<p>book.user.add(user)</p>
</blockquote>
</blockquote>
<p>为了方便你,我上传了一个固定版本的应用程序</p>
<p><a href="https://github.com/ibrahim12/stackoverflow_question_solve" rel="nofollow noreferrer">https://github.com/ibrahim12/stackoverflow_question_solve</a></p>