现在我是heroku的新手,正在尝试在heroku上部署django应用程序。只需遵循说明,它就成功了,我可以在heroku中进行测试。 但是在将本地数据库从sqlite更改为postgres之后,由于该错误,我无法走得更远。它可能与数据库有关。当我将所有应用程序推送到heroku时,我的应用程序在本地基础上仍然运行良好,但在heroku中却无法运行。
base.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
db_from_env = dj_database_url.config()
DATABASES['default'].update(db_from_env)
调试模式下的错误消息
ProgrammingError at /
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
^
Request Method: GET
Request URL: https://happybom.herokuapp.com/
Django Version: 2.0.4
Exception Type: ProgrammingError
Exception Value:
relation "django_session" does not exist
LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
^
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py in _execute, line 85
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.6.4
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python36.zip',
'/app/.heroku/python/lib/python3.6',
'/app/.heroku/python/lib/python3.6/lib-dynload',
'/app/.heroku/python/lib/python3.6/site-packages']
heroku日志
2018-06-27T16:19:46.500148+00:00 app[api]: Starting process with command `bash` by user txxx@gmail.com
2018-06-27T16:19:54.976946+00:00 heroku[run.8196]: Awaiting client
2018-06-27T16:19:55.035413+00:00 heroku[run.8196]: Starting process with command `bash`
2018-06-27T16:19:55.078847+00:00 heroku[run.8196]: State changed from starting to up
2018-06-27T16:20:17.457935+00:00 heroku[run.8196]: Client connection closed. Sending SIGHUP to all processes
2018-06-27T16:20:17.995204+00:00 heroku[run.8196]: Process exited with status 129
2018-06-27T16:20:18.015161+00:00 heroku[run.8196]: State changed from up to complete
2018-06-27T16:21:37.988762+00:00 app[api]: Starting process with command `bash` by user txxx@gmail.com
2018-06-27T16:21:49.979009+00:00 heroku[run.2682]: Awaiting client
2018-06-27T16:21:50.038333+00:00 heroku[run.2682]: Starting process with command `bash`
2018-06-27T16:21:50.171144+00:00 heroku[run.2682]: State changed from starting to up
2018-06-27T16:52:53.428934+00:00 heroku[run.2682]: Client connection closed. Sending SIGHUP to all processes
2018-06-27T16:52:53.967773+00:00 heroku[run.2682]: Process exited with status 129
2018-06-27T16:52:54.005827+00:00 heroku[run.2682]: State changed from up to complete
2018-06-27T17:02:52.720107+00:00 heroku[web.1]: Unidling
2018-06-27T17:02:52.720404+00:00 heroku[web.1]: State changed from down to starting
2018-06-27T17:02:57.851621+00:00 heroku[web.1]: Starting process with command `gunicorn estimate.wsgi`
2018-06-27T17:03:00.563084+00:00 app[web.1]: [2018-06-27 17:03:00 +0000] [4] [INFO] Starting gunicorn 19.8.0
2018-06-27T17:03:00.563690+00:00 app[web.1]: [2018-06-27 17:03:00 +0000] [4] [INFO] Listening at: http://0.0.0.0:35753 (4)
2018-06-27T17:03:00.567579+00:00 app[web.1]: [2018-06-27 17:03:00 +0000] [8] [INFO] Booting worker with pid: 8
2018-06-27T17:03:00.563791+00:00 app[web.1]: [2018-06-27 17:03:00 +0000] [4] [INFO] Using worker: sync
2018-06-27T17:03:00.587739+00:00 app[web.1]: [2018-06-27 17:03:00 +0000] [9] [INFO] Booting worker with pid: 9
2018-06-27T17:03:02.002190+00:00 heroku[web.1]: State changed from starting to up
2018-06-27T17:03:02.895543+00:00 app[web.1]: Internal Server Error: /
2018-06-27T17:03:02.895572+00:00 app[web.1]: Traceback (most recent call last):
2018-06-27T17:03:02.895573+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py", line 191, in _get_session
2018-06-27T17:03:02.895575+00:00 app[web.1]: return self._session_cache
2018-06-27T17:03:02.895576+00:00 app[web.1]: AttributeError: 'SessionStore' object has no attribute '_session_cache'
2018-06-27T17:03:02.895578+00:00 app[web.1]:
2018-06-27T17:03:02.895580+00:00 app[web.1]:
2018-06-27T17:03:02.895579+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2018-06-27T17:03:02.895582+00:00 app[web.1]: Traceback (most recent call last):
2018-06-27T17:03:02.895583+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
2018-06-27T17:03:02.895584+00:00 app[web.1]: return self.cursor.execute(sql, params)
2018-06-27T17:03:02.895585+00:00 app[web.1]: psycopg2.ProgrammingError: relation "django_session" does not exist
2018-06-27T17:03:02.895586+00:00 app[web.1]: LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...
2018-06-27T17:03:02.895588+00:00 app[web.1]: ^
2018-06-27T17:03:02.895589+00:00 app[web.1]:
2018-06-27T17:03:02.895590+00:00 app[web.1]:
2018-06-27T17:03:02.895591+00:00 app[web.1]: The above exception was the direct cause of the following exception:
heroku数据库状态
heroku pg:info
=== HEROKU_POSTGRESQL_COPPER_URL, DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.4
Created: 2018-06-26 03:07 UTC
Data Size: 7.6 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-globular-10516
=== HEROKU_POSTGRESQL_CHARCOAL_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.4
Created: 2018-04-28 23:05 UTC
Data Size: 7.9 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-shaped-32846
heroku pg:diagnose --app happybom
Report 4264cbec-925d-40d3-ad75-45bee458d28e for happybom::DATABASE_URL
available for one month after creation on 2018-06-27T17:38:29.568775+00:00
GREEN: Connection Count
GREEN: Long Queries
GREEN: Idle in Transaction
GREEN: Indexes
GREEN: Bloat
GREEN: Hit Rate
GREEN: Blocking Queries
GREEN: Sequences
SKIPPED: Load
Error Load check not supported on this plan
答案 0 :(得分:1)
您是否在Heroku上运行迁移?
heroku run python manage.py migrate