【问题标题】:Why am I getting a Programming error in Django's Python shell?为什么我在 Django 的 Python shell 中出现编程错误?
【发布时间】: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


【解决方案1】:

删除 Poll 和 Choice 表并运行 python manage.py syncdb 以根据您当前的 models.py 重新创建它们

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2019-05-03
    • 2020-10-10
    • 2017-12-04
    • 1970-01-01
    相关资源
    最近更新 更多