我正在尝试使用Python / Django在Heroku上构建一个webapp,我只是按照教程设置一个Django项目并将其推送到Heroku。但是,我甚至无法接触正常的Django“它有效!”屏幕。当然,那是因为当我检查heroku ps
时,从来没有任何进程在运行。没有Procfile
但根据教程,对于Django应用程序来说这无关紧要。
当我运行heroku run python manage.py runserver
时,会发生以下错误:
Unhandled exception in thread started by <bound method Command.inner_run of <dja
ngo.contrib.staticfiles.management.commands.runserver.Command object at 0x1ff819
0>>
Traceback (most recent call last):
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/com
mands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/bas
e.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/val
idation.py", line 103, in get_validation_errors
connection.validation.validate_field(e, opts, f)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/v
alidation.py", line 14, in validate_field
db_version = self.connection.get_server_version()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 411, in get_server_version
self.cursor()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/__init_
_.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/mysql/b
ase.py", line 387, in _cursor
self.connection = Database.connect(**kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line
81, in Connect
return Connection(*args, **kwargs)
File "/app/.heroku/venv/lib/python2.7/site-packages/MySQLdb/connections.py", l
ine 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1044, "Access denied for user '<user>
'@'%' to database 'heroku_<####################>?reconnect=true'")
我确实已将DATABASE_URL
设置为CLEARDB_DATABASE_URL
的值。另外,在Django settings.py
中,我按照指示添加了:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
非常感谢任何帮助。
答案 0 :(得分:1)
调用ClearDB后修复了该特定错误。事实证明?reconnect=true
仅适用于Rails应用,应该从Django应用的DATABASE_URL
中删除。