我一直在构建django应用,models.py
包含几个模型:
Customer
Error
Record
当我运行python3 manage.py shell
时,我没有错误:
From myapp.models import Customer, Error, Record
records = Record.objects.all()
print(len(records))
# the same works if I run the query for Customer, Error, etc.
但是,如果我尝试使用psycopg2
进行连接,我发现某些表格无法访问。
cur.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';")
print cursor.fetchall()
[('django_migrations',),
('django_content_type',),
('django_admin_log',),
('auth_group_permissions',),
('auth_group',),
('auth_user_groups',),
('auth_permission',),
('auth_user_user_permissions',),
('django_session',),
('my_app_contactme',),
('my_app_employee',),
('auth_user',),
('Error',),
('my_app_blogpost_category',),
('Customer',),
('Record',)]
cur.execute("SELECT * from Customer")
---------------------------------------------------------------------------
ProgrammingError Traceback (most recent call last) <ipython-input-38-3532e0e20e34> in <module>()
----> 1 cur.execute("SELECT * from Customer")
ProgrammingError: relation "customer" does not exist
LINE 1: SELECT * from Customer
我无法弄清楚为什么Customer
,Error
和Record
会导致通过psycopg2访问时出现问题
答案 0 :(得分:0)
我最终在这里找到答案 - psycopg2 cannot find any tables after connection
cur.execute(""" SELECT * from "Customer" """)