问题描述
settings.py
<$ p
我可以在本地机器上访问我的RDS postresql数据库。 $ p $ DATABASES = {
'default':{
'ENGINE':'django.db.backends.postgresql_psycopg2',
'NAME':'xxxxxxx' ,
'USER':'XXXXXXXX',
'PASSWORD':'XXXXXXXX',
'HOST':'XXXXXXrds.amazonaws.com',
'PORT':' 5432',
}
我把它推到了Heroku中,并且在/ saferdb上得到了一个ProgrammingError / query /
在heroku的manage.py shell中,我尝试访问数据库:
>>> from saferdb.models import question
>>> q = Question.objects.all()
>>> q.count()
出现以下错误:
Traceback(最近调用最后一次):
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/backends /utils.py,第85行,在_execute
中返回self.cursor.execute(sql,params)
psycopg2.ProgrammingError:关系saferdb_question不存在
LINE 1:SELECT COUNT (*)AS__countFROMsaferdb_question
^
上述异常是以下异常的直接原因:
Traceback(最近的最后一次调用):
在< module>文件中的< console>,第1行
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py,第387行,计入
返回self.query.get_count (using = self.db)
在get_count $中的/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/query.py第491行b $ b number = obj.get_aggregation(using,['__count'])['__ count']
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/ models / sql / query.py,第476行,在get_aggregation
result = compiler.execute_sql(SINGLE)
文件/app/.heroku/python/lib/python3.6/site-packages/ django / db / models / sql / compiler.py,第1063行,在execute_sql中
cursor.execute(sql,params)
文件/app/.heroku/python/lib/python3.6/在执行
返回超级()。执行(sql,params)
文件/app/.heroku/python/lib /python3.6/site-packages/django/db/backends/utils.py,第68行,执行
返回self._execute_with_wrappers(sql,pa rams,many = False,executor = self._execute)
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py,第77行,在_execute_with_wrappers
中返回executor(sql,params,many,context)
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py ,第85行,在_execute
中返回self.cursor.execute(sql,params)
文件/app/.heroku/python/lib/python3.6/site-packages/django/db/ utils.py,第89行,在__exit__
中从exc_value提高dj_exc_value.with_traceback(traceback)
文件/app/.heroku/python/lib/python3.6/site-packages/django/db /backends/utils.py,第85行,在_execute
中返回self.cursor.execute(sql,params)
django.db.utils.ProgrammingError:关系saferdb_question不存在
LINE 1:SELECT COUNT(*)AS__countFROMsaferdb_question
^
我有类似的问题e,也适用于Heroku应用上的Django。我使用创建我的应用程序。在settings.py中,默认的
数据库是。
您可以在settings.py中禁用它,或者将env var设置为正确的值。
I can access my RDS postresql database on a local machine no problem.
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'xxxxxxx',
'USER': 'XXXXXXXX',
'PASSWORD': 'XXXXXXXX',
'HOST': 'XXXXXXrds.amazonaws.com',
'PORT': '5432',
}
I pushed this to Heroku and I get a ProgrammingError at /saferdb/query/
In manage.py shell on heroku I tried to access the database:
>>> from saferdb.models import Question
>>> q = Question.objects.all()
>>> q.count()
got the following error:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "saferdb_question" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "saferdb_question"
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py", line 387, in count
return self.query.get_count(using=self.db)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/query.py", line 491, in get_count
number = obj.get_aggregation(using, ['__count'])['__count']
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/query.py", line 476, in get_aggregation
result = compiler.execute_sql(SINGLE)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1063, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "saferdb_question" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "saferdb_question"
^
I had a similar issue, also for a Django on Heroku app. I used the heroku-django-template to create my app. In settings.py, the default
database is overwritten by the environment variable DATABASE_URL
.
You can either disable that in the settings.py or set the env var to the correct value.
这篇关于无法在heroku上进行RDS查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!