我是Python和Django的新手并且一步一步跟随"django / docs / intro / tutorial01.txt"。起初,一切顺利,直到我去765行。 我试图调试,但它不起作用
>>> q.choice_set.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 71, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 96, in __iter__
self._fetch_all()
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 220, in iterator
for row in compiler.results_iter():
File "D:\Program Files\Python27\lib\site-packages\django\db\models\sql\compile
r.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "D:\Program Files\Python27\lib\site-packages\django\db\models\sql\compile
r.py", line 781, in execute_sql
cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 53, in execute
return self.cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\utils.py", line 99
, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 53, in execute
return self.cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\sqlite3\b
ase.py", line 450, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: no such column: polls_choice.question_text_id
>>> q.choice_text_set.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Question' object has no attribute 'choice_text_set'
>>> q.choice_set.all()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 71, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 96, in __iter__
self._fetch_all()
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "D:\Program Files\Python27\lib\site-packages\django\db\models\query.py",
line 220, in iterator
for row in compiler.results_iter():
File "D:\Program Files\Python27\lib\site-packages\django\db\models\sql\compile
r.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "D:\Program Files\Python27\lib\site-packages\django\db\models\sql\compile
r.py", line 781, in execute_sql
cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 69, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 53, in execute
return self.cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\utils.py", line 99
, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\util.py",
line 53, in execute
return self.cursor.execute(sql, params)
File "D:\Program Files\Python27\lib\site-packages\django\db\backends\sqlite3\b
ase.py", line 450, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: no such column: polls_choice.question_text_id
任何建议,提前谢谢。
答案 0 :(得分:3)
有两种可能性来解决此错误 1)在执行syncdb之后,您为模型添加了额外的字段。 2)你在django中为model.py文件添加了新类。
解决方法是:
首先使用命令
向南安装 for windows: **easy_install south** //for that you need to go to the script folder of python folder in c drive.
for linux: **sudo easy_install south**
然后按照此处migration tutorials
中包含的步骤操作step1- python manage.py schemamigration your_app_name --initial
step-2 python manage.py migrate your_app_name
如果您对模型进行了任何更改,那么
1) python manage.py schemamigration your_app_name --auto
2) python manage.py migrate your_app_name
希望这会对你有所帮助。
答案 1 :(得分:1)
确保您遵循正在使用的Django版本的正确教程。您已链接到主分支中的文档,最终将成为Django 1.7。如果您使用的是Django 1.6,请使用1.6 tutorial。
我建议您使用正确的文档再次启动教程。第二次通过会更快。如果再次卡住,请更新您的问题。祝你好运!