python - psycopg2 找不到表
问题描述
我有一个 Django 休息框架 API。
我正在尝试使用 PostgreSQL 和 psycopg2 从中访问一些数据。
import psycopg2
try:
connection = psycopg2.connect(user="*****",
password='*****',
host="127.0.0.1",
port="5432",
database="locations")
cursor = connection.cursor()
postgreSQL_select_Query = "select * from KnownLocations"
cursor.execute(postgreSQL_select_Query)
print("Selecting rows from find_second_gdt_points")
records = cursor.fetchall()
print(records)
except (Exception, psycopg2.Error) as error:
print("Error while fetching data from postgreSQL", error)
finally:
# Closing connection
if connection:
cursor.close()
connection.close()
print("Connection to DB is closed.")
运行脚本时出现以下错误:
Error while fetching data from PostgreSQL relation "knownlocations" does not exist
LINE 1: select * from KnownLocations
但是在终端中打印数据库时,该表确实存在。
locations=# \dt
List of relations
Schema | Name | Type | Owner
--------+----------------------------------+-------+-------
public | KnownLocations | table | yovel
public | auth_group | table | yovel
public | auth_group_permissions | table | yovel
public | auth_permission | table | yovel
public | auth_user | table | yovel
public | auth_user_groups | table | yovel
public | auth_user_user_permissions | table | yovel
public | authtoken_token | table | yovel
public | django_admin_log | table | yovel
public | django_content_type | table | yovel
public | django_migrations | table | yovel
public | django_session | table | yovel
public | find_second_gdt_points | table | yovel
public | threelocationstrian_locationinfo | table | yovel
(14 rows)
解决方案
推荐阅读
- python - 读取csv字符串的函数
- javascript - 页面加载后响应式语音不起作用,单击需要
- networking - 无法访问 wifi 路由器管理门户
- python - 使用 Pandas 将 SAS 转换为 Python
- php - Laravel 推送器未在 Localhost 中进行身份验证,但在 Development Server 中进行了身份验证
- css - 添加具有背景 CSS 属性的视频
- sql - SYS_REFCURSOR 作为函数中的输出参数
- excel - Excel 列表中的部分搜索列并填充相邻单元格
- godot - Godot GDScript“参数太多”错误
- python - opencv - 如何检查轮廓位置