Q&A
책을 따라하다가 막히는 부분이 있나요?
질문을 남겨주세요.
하지만, 책을 끝까지 읽고 나면 이 페이지도 만드실 수 있을거에요.
p.575 django.db.utils.OperationalError 에러가 발생합니다
3 years, 3 months ago
joori다른 분들이 올린 질문들을 참고하여서 postgresql를 도입하려 하는 중입니다.
그런데 다른 문제는 대부분 해결이 된 거 같은데 이상하게 실행이 되지 않습니다 ㅜㅜ
docker-compose build까지는 되는데, docker-compose up을 입력하였을 때 아래와 같은 오류가 발생합니다.
Starting do_it_django_a_to_z_db_1 ... done
Recreating do_it_django_a_to_z_web_1 ... done
Attaching to do_it_django_a_to_z_db_1, do_it_django_a_to_z_web_1
db_1 | 2021-07-07 04:40:51.145 UTC [1] LOG: starting PostgreSQL 12.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0) 8.3.0, 64-bit
db_1 | 2021-07-07 04:40:51.145 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2021-07-07 04:40:51.145 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2021-07-07 04:40:51.148 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2021-07-07 04:40:51.162 UTC [19] LOG: database system was interrupted; last known up at 2021-07-05 08:54:44 UTC
db_1 | 2021-07-07 04:40:51.305 UTC [19] LOG: database system was not properly shut down; automatic recovery in progress
db_1 | 2021-07-07 04:40:51.307 UTC [19] LOG: redo starts at 0/16489C8
db_1 | 2021-07-07 04:40:51.307 UTC [19] LOG: invalid record length at 0/1648A00: wanted 24, got 0
db_1 | 2021-07-07 04:40:51.307 UTC [19] LOG: redo done at 0/16489C8
db_1 | 2021-07-07 04:40:51.318 UTC [1] LOG: database system is ready to accept connections
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
db_1 | 2021-07-07 04:41:11.359 UTC [26] FATAL: role "do_it_django_db_user" does not exist
web_1 | Exception in thread django-main-thread:
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
web_1 | psycopg2.OperationalError: FATAL: role "do_it_django_db_user" does not exist
web_1 |
web_1 |
web_1 | The above exception was the direct cause of the following exception:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
web_1 | self.run()
web_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run
web_1 | self._target(*self._args, **self._kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
web_1 | self.check_migrations()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 459, in check_migrations
web_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
web_1 | self.loader = MigrationLoader(self.connection)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
web_1 | self.build_graph()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
web_1 | self.applied_migrations = recorder.applied_migrations()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
web_1 | if self.has_table():
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
web_1 | with self.connection.cursor() as cursor:
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
web_1 | return self._cursor()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
web_1 | self.ensure_connection()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
web_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
web_1 | return func(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
web_1 | django.db.utils.OperationalError: FATAL: role "do_it_django_db_user" does not exist
web_1 |
[docker-compose.yml]
[Dockerfile]
[settings.py]
[.env.dev]
목록보기
jinioji 3 years, 3 months ago
올려주신 설정 파일에는 문제가 없어 보입니다.
에러 로그 중 다음 부분이 문제로 보이네요.
web_1 | psycopg2.OperationalError: FATAL: role "do_it_django_db_user" does not exist
혹시 빌드 할 때 psycopg2에서 에러 안 났나요?
에러가 났다면 psycopg2 대신에 psycopg2-binary로 인스톨하고 다시 빌드 해 보시고요...
그것도 아니라면 확실치 않지만 DB 쪽 문제 아닐까 생각됩니다.
# docker-compose down -v
최후의 수단으로 전부 삭제하시고 다시 한번 해 보시는건 어떨까요?
잘 해결이 되었으면 좋겠습니다.
Updated: July 7, 2021, 4:24 p.m.
joori 3 years, 3 months ago
psycopg2 에서 에러가 발생해서 psycopg2-binary로 인스톨을 했었습니다.
에러 발생 이유는 알겠는데, 해결방법을 전혀 모르겠어서
말씀하신대로 전부 삭제를 하고 다시 해보니 되네요!
감사합니다.
Updated: July 7, 2021, 5:05 p.m.
Leave a Comment: