首页 > 解决方案 > ProgrammingError:关系不存在

问题描述

当我尝试使用 psycopg2 从数据框中将数据插入现有表中时,我遇到了错误。

我已经验证了:

这是我的数据框:

标题 技能
内容作家/编辑 技能创意写作 5 年
内容作家/编辑 编辑4年

这是我的代码:

def write_to_skills_table():
 cursor = conn.cursor()
 for index, row in skill_df.iterrows():
  cursor.execute("INSERT INTO skill VALUES (%s, %s)", row)

 conn.commit()

任何帮助将非常感激!

编辑:这是完整的错误消息:

ProgrammingError                          Traceback (most recent call last)

<ipython-input-68-09d3a90be86a> in <module>()
    180 skill(p_tag)
    181 create_connection()
--> 182 write_to_skills_table()
    183 close_connection()

<ipython-input-68-09d3a90be86a> in write_to_skills_table()
    159 
    160   for index, row in skill_df.iterrows():
--> 161     cursor.execute("INSERT INTO skill VALUES (%s, %s)", row)
    162 
    163   conn.commit()

ProgrammingError: relation "skill" does not exist
LINE 1: INSERT INTO skill VALUES ('Content Writer/Editor', 'Skills C...

标签: pythonpython-3.xpandaspostgresql

解决方案


推荐阅读