我正在使用Django 1.4.5并遵循Django Docs
的Django 1.4教程我有两个模型,在models.py中定义如下:
from django.db import models
# Create your models here.
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
在Django shell中创建Poll实例后,我尝试使用Poll.objects.all()。delete()删除它并收到以下错误:
DatabaseError: no such column: polls_choice.poll_id
以下是整个Traceback
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 513, in delete
collector.collect(del_query)
File "/Library/Python/2.7/site-packages/django/db/models/deletion.py", line 175, in collect
if not sub_objs:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 130, in __nonzero__
iter(self).next()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 118, in _result_iter
self._fill_cache()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 892, in _fill_cache
self._result_cache.append(self._iter.next())
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 291, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 40, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 344, in execute
return Database.Cursor.execute(self, query, params)
DatabaseError: no such column: polls_choice.poll_id
感谢。
答案 0 :(得分:0)
这是由以下选项之一产生的通用错误:
1-您在创建Poll
模型之前已同步数据库。
2-您根本没有同步数据库。
尝试:
python manage.py syncdb
manage.py
位于Django项目的根目录中。