简体   繁体   English

在Heroku上使用Python / Django拒绝对ClearDB数据库的访问

[英]Access denied to ClearDB database using Python/Django on Heroku

I'm trying to build a webapp on Heroku using Python/Django, and I just followed the tutorial to set up a Django project and push it to Heroku. 我正在尝试使用Python / Django在Heroku上构建Web应用程序,而我只是按照教程设置了Django项目并将其推送到Heroku。 However, I can never even get to the normal Django "It worked!" 但是,我什至无法使用普通的Django“它有效!” screen. 屏幕。 Of course, that is because when I check heroku ps , there are never any processes running. 当然,这是因为当我检查heroku ps ,从来没有任何进程在运行。 There is no Procfile but according to the tutorial, that shouldn't matter for a Django app. 没有Procfile但是根据教程,这对于Django应用来说无关紧要。

When I run heroku run python manage.py runserver , the following error occurs: 当我运行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'")

I did already set my DATABASE_URL to the value of CLEARDB_DATABASE_URL . 我已经将DATABASE_URL设置为CLEARDB_DATABASE_URL的值。 Also, in the Django settings.py , I added as instructed: 另外,在Django settings.py ,我按照指示添加:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}

Any help would be greatly appreciated. 任何帮助将不胜感激。

That particular error was fixed after calling ClearDB. 调用ClearDB之后,该特定错误已修复。 Turns out that the ?reconnect=true is only for Rails apps, and should be removed from the DATABASE_URL for Django apps. 原来, ?reconnect=true仅适用于Rails应用程序,对于Django应用程序应从DATABASE_URL删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM