我最近将django数据库从sqlite切换到mysql。我已经安装了heroku的免费mysql数据库,名为cleardb,我正在使用以下文档:https://devcenter.heroku.com/articles/cleardb. 我可以使用以下命令创建/安装应用程序并获取数据库的url:
heroku addons:create cleardb:ignite
heroku config | findstr CLEARDB_DATABASE_URL
heroku config | set DATABASE_URL= # MySQL database url retrieved from above line
完成此操作后,使用我的数据库更改(在本地工作)将所有内容推送到heroku并打开应用程序,我得到以下回溯:
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template error:
In template /app/profiles/templates/base.html, error at line 0
2002
1 :
2 : <!DOCTYPE html>
3 : {% load staticfiles %}
4 :
5 : {% block styles %}
6 : {% endblock %}
7 :
8 :
9 : <style type="text/css">
10 :
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
194. self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in get_new_connection
236. return Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/__init__.py" in Connect
86. return Connection(*args,**kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in __init__
204. super(Connection, self).__init__(*args,**kwargs2)
The above exception ((2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args,**callback_kwargs)
File "/app/profiles/views.py" in home
17. return render(request, template, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/shortcuts.py" in render
36. content = loader.render_to_string(template_name, context, request, using=using)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
62. return template.render(context, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
175. return self._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
167. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
155. return compiled_parent._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
167. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
67. result = block.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
211. nodelist.append(node.render_annotated(context))
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
168. len_values = len(values)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __len__
254. self._fetch_all()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
1179. self._result_cache = list(self._iterable_class(self))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1061. cursor = self.connection.cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in cursor
255. return self._cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in _cursor
232. self.ensure_connection()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
194. self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in get_new_connection
236. return Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/__init__.py" in Connect
86. return Connection(*args,**kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in __init__
204. super(Connection, self).__init__(*args,**kwargs2)
Exception Type: OperationalError at /
Exception Value: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
我仍在学习,不知道如何解决这个回溯。如果你能帮我理解我做错了什么,那就太好了。
暂无答案!
目前还没有任何答案,快来回答吧!