I’m trying to setup PostreSQL for Django deployed on Heroku. I am following along with the official Heroku doc titled Concurrency and Database Connections in Django | Heroku Dev Center
I am trying to configure the pgbouncer buildpack.
When I pushed my changes to Heroku, I received: “OperationalError at /, server does not support SSL, but SSL was required”. So I Google: ‘heroku ssl django operationalerror pgbouncer’ which turns up a known issue described in an Issue on the official Heroku GitHub repo titled: “django.db.utils.OperationalError: server does not support SSL, but SSL was required #118”
That is my issue precisely. A number of other users chimed in with a solution that seems to resolve the issue for all of them. The solution is to add:
del DATABASES['default']['OPTIONS']['sslmode']
after:
django_heroku.settings(locals())
When I made that change, that eliminated the SSL traceback successfully (Hooray!) but introduces a new problem that no one else on GitHub seems to report. Here is my new traceback:
ProgrammingError at /
column accounts_authtoggle.enable_protection does not exist
LINE 1: SELECT “accounts_authtoggle”.“id”, “accounts_authtoggle”."en…
Request Method:
GET
Request URL:
https://tarot-juicer-next-iter.herokuapp.com/
Django Version:
2.2.13
Exception Type:
ProgrammingError
Exception Value:
column accounts_authtoggle.enable_protection does not exist
LINE 1: SELECT “accounts_authtoggle”.“id”, “accounts_authtoggle”."en…
^
Exception Location:
/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py in _execute, line 84
Python Executable:
/app/.heroku/python/bin/python
Python Version:
3.6.12
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’]
Server time:
Fri, 5 Feb 2021 17:58:56 +0000
Logged into my Heroku shell, when I attempt to run $ python manage.py makemigrations
, it points to a key error at the line I just added inside my settings.py
as you can see in the traceback here:
$ python manage.py makemigrations
Traceback (most recent call last):
File “manage.py”, line 21, in
main()
File “manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “/app/.heroku/python/lib/python3.6/site-packages/django/core/management/init.py”, line 381, in execute_from_command_line
utility.execute()
File “/app/.heroku/python/lib/python3.6/site-packages/django/core/management/init.py”, line 325, in execute
settings.INSTALLED_APPS
File “/app/.heroku/python/lib/python3.6/site-packages/django/conf/init.py”, line 79, in getattr
self._setup(name)
File “/app/.heroku/python/lib/python3.6/site-packages/django/conf/init.py”, line 66, in _setup
self._wrapped = Settings(settings_module)
File “/app/.heroku/python/lib/python3.6/site-packages/django/conf/init.py”, line 157, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File “/app/.heroku/python/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/app/tarot_juicer/settings.py”, line 149, in
del DATABASES[‘default’][‘OPTIONS’][‘sslmode’]
KeyError: ‘OPTIONS’
Here are the relevant lines in my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
}
# HEROKU - replace / update default database with heroku postgresql
# db_from_env = dj_database_url.config(conn_max_age=600, ssl_require=True)
DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
My full settings.py can be found here.
The contents of my Procfile is a single line which reads: web: bin/start-pgbouncer-stunnel gunicorn tarot_juicer.wsgi
I’m running Python 3.6.12 and Django 2.2.
edit: Moved tracebacks into their own pastebins
edit: Moved tracebacks back into the forum thread and removed pastebin links
edit: Changed traceback wrapper formatting from syntax highlighting to general quotes, trying to make it a little bit more readable