几周前我开始了 django 教程第 1 部分,回来后发现 Poll 已更改为 Question。当我第一次尝试更改 models.py 文件时
class Poll(models.Model):
至
class Question(models.Model):
运行后:
python manage.py sql polls
我收到以下错误:
NameError: name 'Poll' is not defined
我的第一个问题是,如果我想更改模型文件中类的名称,我该怎么做才能避免这样的错误?
因此,我将其命名为 Poll 以消除此错误。但是,当我到达教程中的部分时,它说:
进入 shell 后,探索数据库 API:
从 polls.models 导入民意调查,选择
轮询.objects.all()
但我收到以下错误:
File "<console>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 93, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 108, in __len__
self._result_cache.extend(self._iter)
File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 317, in iterator
for row in compiler.results_iter():
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 775, in results_iter
for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 41, in execute
return self.cursor.execute(sql, params)
File "/usr/lib/python2.6/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 "/usr/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 120, in execute
return self.cursor.execute(query, args)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 201, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1054, "Unknown column 'polls_poll.question_text' in 'field list'")
所以,只是想知道这里出了什么问题。
谢谢