0

I was new to Python and Django and followed "django / docs / intro / tutorial01.txt" step by step. At first, everything went well until I went to line 765. I tried to debug, but it din't work

>>> 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

Any advice, thanks in advance.

Max
  • 23
  • 1
  • 2

2 Answers2

2

There are two possibilities that to get this error 1) You added extra field to model after doing the syncdb. 2) you added new class to model.py file in django.

Solution for this is:

First install south by using command

    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**  

Then follow the steps which are included here migration tutorials

step1- python manage.py schemamigration your_app_name --initial

step-2 python manage.py migrate your_app_name

if you made any changes in model then

 1) python manage.py schemamigration your_app_name --auto
 2) python manage.py migrate your_app_name

Hope this will help you.

Wagh
  • 4,202
  • 5
  • 39
  • 62
1

Make sure you are following the correct tutorial for the version of Django that you are using. You have linked to the docs in the master branch, which will eventually become Django 1.7. If you are using Django 1.6, then use the 1.6 tutorial.

I recommend you start the tutorial again, using the correct docs. It will be quicker the second time through. If you get stuck again, then please update your question. Good luck!

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • thanks very much for your advice. It turned out there was something wrong with the table I synced during process. I really should restart the process. – Max Dec 08 '13 at 12:48