DATABASES = {'default': dj_database_url.config(os.environ['DATABASE_URL'], conn_max_age=1800)}
DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<databasename>
web_1 | [2020-11-03 16:35:59 +0000] [7] [ERROR] Error handling request /NDCs/
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 134, in handle
web_1 | self.handle_request(listener, req, client, addr)
web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 175, in handle_request
web_1 | respiter = self.wsgi(environ, resp.start_response)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 131, in __call__
web_1 | signals.request_started.send(sender=self.__class__, environ=environ)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 177, in send
web_1 | return [
web_1 | File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
web_1 | (receiver, receiver(signal=self, sender=sender, **named))
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/__init__.py", line 46, in reset_queries
web_1 | for conn in connections.all():
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 229, in all
web_1 | return [self[alias] for alias in self]
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 229, in <listcomp>
web_1 | return [self[alias] for alias in self]
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 211, in __getitem__
web_1 | self.ensure_defaults(alias)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 176, in ensure_defaults
web_1 | conn.setdefault('ATOMIC_REQUESTS', False)
web_1 | AttributeError: 'str' object has no attribute 'setdefault'
1. Since this app is dockerized, I have my existing env vars in my docker-compose-prod.yml file. Is that where I should list DATABASE_URL? Like:
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<databasename>
2. Does the below formatting look correct to you from my settings.py? I am running into issues with the env var DATABASE_URL and getting this error: Environment variable "{}" not set'
DATABASES = {
'default': dj_database_url.config(env("DATABASE_URL"), default="postgres://postgres@db/postgres", conn_max_age=1800),
'ENGINE': 'django.db.backends.postgresql',
}
3. I am also getting this error when running locally. Do you have any advice for troubleshooting?
web_1 | [2020-11-03 16:35:59 +0000] [7] [ERROR] Error handling request /NDCs/web_1 | Traceback (most recent call last):web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 134, in handleweb_1 | self.handle_request(listener, req, client, addr)web_1 | File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 175, in handle_requestweb_1 | respiter = self.wsgi(environ, resp.start_response)web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 131, in __call__web_1 | signals.request_started.send(sender=self.__class__, environ=environ)web_1 | File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 177, in sendweb_1 | return [web_1 | File "/usr/local/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>web_1 | (receiver, receiver(signal=self, sender=sender, **named))web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/__init__.py", line 46, in reset_queriesweb_1 | for conn in connections.all():web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 229, in allweb_1 | return [self[alias] for alias in self]web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 229, in <listcomp>web_1 | return [self[alias] for alias in self]web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 211, in __getitem__web_1 | self.ensure_defaults(alias)web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 176, in ensure_defaultsweb_1 | conn.setdefault('ATOMIC_REQUESTS', False)web_1 | AttributeError: 'str' object has no attribute 'setdefault'
On 5 Nov 2020, at 04:11, Marc Johnson <marcjoh...@gmail.com> wrote:
Hi David,
Thanks again for the feedback. When I remove the 'ENGINE' variable I get the error saying settings.DATABASES is improperly configured, as shown in the snapshot attached below.
But when I add the ENGINE variable, like listed below, I get an 'Internal Server Error':
DATABASES = {
'default': dj_database_url.config(env='DATABASE_URL', conn_max_age=1800),
'ENGINE': 'django.db.backends.postgresql',
}
My db settings in my docker-compose.yml file are also provided below:
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- "DATABASE_URL=postgresql://postgres:P#ssw0rd@postgres:5432/ndc_data"
- "POSTGRES_HOST_AUTH_METHOD=trust"
- "POSTGRES_PASSWORD=P#ssw0rd"
- "POSTGRES_USER=postgres"
- "POSTGRES_DB=ndc_data"
- "POSTGRES_HOST=postgres"
networks:
- default
How am I screwing this up so royally!? I did not expect this connection to involve so much troubleshooting.