【问题标题】:ProgrammingError: relation "users" does not exist - PostgreSQLProgrammingError:关系“用户”不存在 - PostgreSQL
【发布时间】:2017-05-25 10:38:02
【问题描述】:

今天刚开始使用 postgreSQL 和 Python。我正在尝试使用“psycopg2”库执行查询,但出现以下错误:“ProgrammingError:关系“用户”不存在”

在我的 pSQL cmd 行中,我可以看到我的“用户”表全部小写,没有大写,所以不确定发生了什么。我将在下面粘贴我的查询。提前感谢您的任何帮助!

conn = psycopg2.connect(host="127.0.0.1", database="test", user="postgres", password="password")
    cur = conn.cursor()
    cur.execute('SELECT * FROM users WHERE username = %s AND password = %s', (username, password))

注意 当我运行 \dt 时,我得到以下信息

         List of relations
 Schema | Name  | Type  |  Owner
--------+-------+-------+----------
 public | users | table | postgres

【问题讨论】:

  • 数据库'test'上有用户表吗?
  • 除了@Vsevolod 的评论 - 确保此表在公共架构中,否则您还必须包含架构名称。
  • 大家好,是的,用户表存在于数据库中,是的,该表在公共模式中
  • 请运行psql -h 127.0.0.1 test -U postgres -c "SELECT * FROM users limit 1"
  • 你确定你连接到同一个数据库吗?

标签: python sql postgresql psycopg2


【解决方案1】:

我曾经在工作中遇到过这种情况,我被告知您可能应该尝试以下方法:

python manage.py makemigrations,然后是 python manage.py migrate。就我而言,无需进行任何迁移,但它已多次解决了我的“关系不存在”问题!

【讨论】:

    猜你喜欢
    • 2016-05-05
    • 2018-10-25
    • 2013-05-06
    • 2020-03-06
    • 2023-03-14
    • 1970-01-01
    • 2018-05-23
    • 2016-05-01
    • 2016-04-11
    相关资源
    最近更新 更多