2017-08-01 75 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

回答