我试图通过管理网站访问我的应用程序,而这样做Django的教程,并正在此错误:为什么我的数据库抛出一个错误?
DatabaseError at /admin/polls/poll/ (1054, "Unknown column 'polls_poll.question' in 'field list'")
本来我把我的模型使用问题类,而错误地使用1.6版本的该教程,但切换到1.54版本,并不得不重新命名我的问题类为民意调查。然后我重新启动了数据库。我正在使用MySQL。
现在,每次我从管理网站点击“投票”它会引发上述错误。
我试图冲洗我的数据库和resyncing,但没有奏效。
这里是我的models.py代码:
from django.db import models
import datetime
from django.utils import timezone
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text
以下是完整回溯:
Internal Server Error: /admin/polls/poll/
Traceback (most recent call last):
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/contrib/admin/options.py", line 372, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 202, in inner
return view(request, *args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/utils/decorators.py", line 21, in bound_func
return func(self, *args2, **kwargs2)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1285, in changelist_view
'selection_note': _('0 of %(cnt)s selected') % {'cnt': len(cl.result_list)},
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 106, in __len__
self._result_cache = list(self.iterator())
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/query.py", line 317, in iterator
for row in compiler.results_iter():
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
for rows in self.execute_sql(MULTI):
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/backends/util.py", line 41, in execute
return self.cursor.execute(sql, params)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 128, in execute
six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2])
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 120, in execute
return self.cursor.execute(query, args)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/MySQLdb/cursors.py", line 201, in execute
self.errorhandler(self, exc, value)
File "/Users/MyClean/anaconda/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1054, "Unknown column 'polls_poll.question' in 'field list'")
请提供完整的回溯。另外,你确定列'polls_poll.question'存在吗? – aIKid
尝试删除数据库并再次同步 – akonsu
@aIKid我刚添加完整的回溯。 – MikeBrody