python - 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...
解决方案
推荐阅读
- textarea - 如何实现多行输出
- css - 仅在显示引导模式后才应用 CSS 动画
- html - 粘性位置 + 顶部的 Flex 对齐锚点
- java - Thymeleaf 未在页面上显示正确的字符串,但从模型中正确打印
- javascript - Cheerio 找到以字符串开头的类的孩子
- javascript - getConnectedNodes 方向参数
- kotlin - 为什么服务器会出现 Kotlin 编译错误?
- javascript - 如何合并两个数组并按位置排列结果?
- javascript - Firebase 身份验证和 MongoDB 数据库
- java - 获取 java.lang.IllegalAccessError:当我尝试将 menuBar 添加到我的程序时,超类访问检查失败