【发布时间】:2014-02-06 07:35:42
【问题描述】:
我正在关注 Django 在 Arch Linux 上使用 PostgreSQL 的 1.6 版教程。到目前为止,我在第 1 部分:
"给Poll 一对Choices。create 调用构造了一个新的
Choice 对象,执行 INSERT 语句,将选项添加到集合中
可用选项并返回新的Choice 对象。 Django 创建
一组用于保持ForeignKey 关系的“另一面”
(例如投票的选择),可以通过 API 访问。
>>> p = Poll.objects.get(pk=1)
# Display any choices from the related object set -- none so far.
>>> p.choice_set.all()
[]
当我运行 p.choice_set.all() 时,我的 shell 中出现错误,而不是空列表:
ProgrammingError: column "poll_id" of relation "polls_choice" does not exist
这是我第一次在教程中看到“choice_set”,我不确定它的作用。我尝试了整个练习几次,直到现在一切正常——我无法弄清楚我做错了什么。
【问题讨论】:
-
你做了syncdb之后有没有换过模型?
-
尝试使用drop命令手动删除数据库并再次运行syncdb。
-
@crazydiv 谢谢,成功了!
标签: django postgresql python-2.7