我一直在构建一个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访问的问题
最后我在这里找到了答案-psycopg2 cannot find any tables after connection
相关问题 更多 >
编程相关推荐