2016-09-06 108 views
-1

每当我运行程序时,我得到以下错误:为什么我得到的错误:OperationalError在/表/没有这样的表:table_book

OperationalError at /table/ 
no such table: table_book 

它说,有一个在第7行的错误我模板文件。

这里是我的template.html:

<table> 
<tr> 
    <th>author</th> 
    <th>title</th> 
    <th>publication year</th> 
</tr> 
{% for b in obj %} 
<tr> 
    <td>{{ b.author }}</td> 
    <td>{{ b.title }}</td> 
    <td>{{ b.publication_year }}</td> 
</tr> 
{% endfor %} 
</table> 

这里是我的views.py:

from django.shortcuts import render 

def display(request): 
    return render(request, 'template.tmpl', {'obj': models.Book.objects.all()}) 

这里是我的models.py:

from django.db import models 

class Book(models.Model): 
    author = models.CharField(max_length = 20) 
    title = models.CharField(max_length = 40) 
    publication_year = models.IntegerField() 

这里是我的网址.py:

​​

有人可以告诉我什么是错的?

回答

0

数据库表table_book丢失。你是否运行makemigrations并迁移?

+0

哦,我忘了迁移...我现在就去做。 –