2016-09-06 34 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

哦,我忘了遷移...我現在就去做。 –

相關問題