2017-08-01 118 views
0

我一直在建设一个Django应用程序访问和models.py包括一些模型时丢失:Django的模型psycopg2

  • 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 

我想不通为什么CustomerErrorRecord是造成问题通过psycopg2

回答