Django app RANDOMLY losing connection to Postgresql database - django

I've been looking everywhere but cannot seem to find anyone with my same problem. Here's my situation...
Django App: Running on Centos7 Vagrant guest 10.0.0.2 connecting to DB
Postgresql-10 DB: Running on Centos7 Vagrant guest 10.0.0.1 serving the Django app, also has pgAdmin4 running on it
When I bring these vagrant machines up they are able to initially connect. I notice when I leave them idle for periods of time then the Django app cannot connect any longer to the DB. Even weirder, most of the time, but not all the time, I simply needed to restart the postgresql database service and it would be able to connect again. Right now that's not even the case so I can no longer ignore this problem by just restarting the DB service.
Any ideas on what could be going on here? I've tried a couple things but nothing seems to work. My feeling is it's something on the database machine causing issues since like I said usually this just required a simple restart of the DB service to fix.
I'm completely confused by how it just loses connection sometimes randomly.
Below is the error that is printed out when I try to restart the django app and run "python3 manage.py makemigrations"
-----> Making database migrations
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 92, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 216, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/usr/local/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "10.0.0.1" and accepting
TCP/IP connections on port 5432?

Related

Django on Ubuntu giving libpq version 10 error [duplicate]

This question already has answers here:
How can I solve Postgresql SCRAM authentication problem?
(17 answers)
SCRAM authentication requires libpq version 10 or above in
(3 answers)
Closed 10 days ago.
I am trying to setup a Django website on linux ubuntu with postgresql, gunicorn and nginx.
However every time I try to start the development server I get this following error:
Traceback (most recent call last):
File "/home/ubuntu/personalserver/manage.py", line 22, in <module>
main()
File "/home/ubuntu/personalserver/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
output = self.handle(*args, **options)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/base.py", line 96, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 114, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
self.build_graph()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
if self.has_table():
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
with self.connection.cursor() as cursor:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 323, in cursor
return self._cursor()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 299, in _cursor
self.ensure_connection()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 281, in ensure_connection
with self.wrap_database_errors:
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 282, in ensure_connection
self.connect()
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 263, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 215, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/ubuntu/personalserver/myprojectenv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: SCRAM authentication requires libpq version 10 or above
I have already tried the following fix: https://stackoverflow.com/a/62808487/15540615
such that this is my conf file:
and this is my password encryption setting:

Create superuser for cvat

I am trying to install cvat, so I am following the Installation guide
The first step run smoothly, however when I try to create a superuser with the command
docker exec -it cvat_server bash -ic 'python3 ~/manage.py createsuperuser'
After a few minutes, I get the following error:
Traceback (most recent call last):
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/venv/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out
Is the server running on host "cvat_db" (172.18.0.3) and accepting
TCP/IP connections on port 5432?
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/django/manage.py", line 21, in <module>
execute_from_command_line(sys.argv)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/venv/lib/python3.8/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 397, in execute
self.check_migrations()
File "/opt/venv/lib/python3.8/site-packages/django/core/management/base.py", line 486, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
self.build_graph()
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/opt/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 33, in inner
return func(*args, **kwargs)
File "/opt/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/venv/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection timed out
Is the server running on host "cvat_db" (172.18.0.3) and accepting
TCP/IP connections on port 5432?
What should I do to fix this and use CVAT?
My Ubuntu version: Ubuntu 22.04.1 LTS
I thought adding Django's authentication system might solve it so I did pip install django-auth but it changed nothing
I have had the same problem but I found a solution. Some user suggested a problem with docker installation here. My way to solve it is:
Remove docker installation completely. This can help.
Install docker from the atp repository:
sudo apt install containerd
sudo apt install docker.io
Do everything as in the CVAT installation guide, but ignore the part about installing Docker and use the commands above. With this solution some comands indicated in the installation guide will require sudo. In the guide:
Instead of docker compose up -d use sudo docker-compose up -d
Run with sudo docker-compose up

django clone project migrate error occured

"django.db.utils.OperationalError" occurred while setting using django cookiecutter.
config\settings\base.py
DATABASES = {
"default": env.db(
"DATABASE_URL",
default="postgres://postgres:root#localhost:5432/instagram",
),
}
C:\dev\clone\instagram>py manage.py migrate
Traceback (most recent call last):
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection
self.connect()
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\postgresql\base.py", line 203, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\dev\clone\instagram\manage.py", line 31, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
utility.execute()
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 460, in execute
output = self.handle(*args, **options)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 98, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\commands\migrate.py", line 91, in handle
self.check(databases=[database])
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\management\base.py", line 487, in check
all_issues = checks.run_checks(
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\checks\model_checks.py", line 36, in check_all_models
errors.extend(model.check(**kwargs))
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\base.py", line 1461, in check
*cls._check_indexes(databases),
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\models\base.py", line 1864, in _check_indexes
connection.features.supports_covering_indexes
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\postgresql\features.py", line 84, in is_postgresql_11
return self.connection.pg_version >= 110000
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\functional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\postgresql\base.py", line 354, in pg_version
with self.temporary_connection():
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 639, in temporary_connection
with self.cursor() as cursor:
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 284, in cursor
return self._cursor()
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 260, in _cursor
self.ensure_connection()
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 243, in ensure_connection
with self.wrap_database_errors:
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 244, in ensure_connection
self.connect()
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\base\base.py", line 225, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\postgresql\base.py", line 203, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\krsai\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError
I modified only this base.py part, but the "migrate" command is not executed and an error occurs. What is the reason?
installed postgresql
create DB name as "instagram"
installed cookiecutter
modified "base.py"
run "py manage.py makemigrations"
error occured
Now I'm using postgresql version 15, could it be the reason of error?
Because I tried to use version 14 also but have same error.
Remove all the migration files, then:
python manage.py makemigrations
python manage.py migrate

password authentication failed for user "djangoadmin"

I am trying to host my website on digitaloceans. on running
python manage.py makeigrations
I get these errors
Traceback (most recent call last):
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "djangoadmin"
FATAL: password authentication failed for user "djangoadmin"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "djangoadmin"
FATAL: password authentication failed for user "djangoadmin"
(venv) djangoadmin#ubuntu-s-1vcpu-1gb-nyc1-01:~/pyapps/pilgrimage_church$ sudo nano .env
[sudo] password for djangoadmin:
(venv) djangoadmin#ubuntu-s-1vcpu-1gb-nyc1-01:~/pyapps/pilgrimage_church$ python manage.py makemigrations
Traceback (most recent call last):
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "djangoadmin"
FATAL: password authentication failed for user "djangoadmin"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 101, in handle
loader.check_consistent_history(connection)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 290, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
if self.has_table():
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 259, in cursor
return self._cursor()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 235, in _cursor
self.ensure_connection()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
self.connect()
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/base/base.py", line 200, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/utils/asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
connection = Database.connect(**conn_params)
File "/home/djangoadmin/pyapps/venv/lib/python3.6/site-packages/psycopg2/__init__.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL: password authentication failed for user "djangoadmin"
FATAL: password authentication failed for user "djangoadmin"
djangoadmin is not in my database at all. I am using Postgresql as my database
However, django admin is an ssh user.
Django database settings:
DATABASES = { 'default':
{ 'ENGINE': 'django.db.backends.postgresql',
'NAME': env.str('NAME'),
'USER': env.str('USER'),
'PASSWORD': env.str('PASSWORD'),
'HOST': 'localhost',
'PORT': '5432', } }
What can I do please? I have reset the password. I have dropped and created a new table. I keep getting this error

Operationalerror: database don't exist

I deleted my postgresql database from pgAdmin III (right click on databases/mydatabase => delete/drop).
Now I want start anew and make the first migration that should create the database but instead it give an error: database don't exist.
Until now I was using sqlite3 and this procedure worked.
What I should do?
Full traceback:
(myvenv) c:\Python34\Scripts\possedimenti\sitopossedimenti>manage.py migrate
Traceback (most recent call last):
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATALE: il database "possedimenti_database" non esis
te
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python34\Scripts\possedimenti\sitopossedimenti\manage.py", line 10, i
n <module>
execute_from_command_line(sys.argv)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\base.py", line 399, in execute
output = self.handle(*args, **options)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\core\ma
nagement\commands\migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 49, in __init__
self.build_graph()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\migr
ations\recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_name
s(self.connection.cursor()):
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 204, in _cursor
self.ensure_connection()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\util
s.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\utils\s
ix.py", line 685, in reraise
raise value.with_traceback(tb)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 199, in ensure_connection
self.connect()
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\base\base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\django\db\back
ends\postgresql\base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "c:\Python34\Scripts\possedimenti\myvenv\lib\site-packages\psycopg2\__ini
t__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATALE: il database "possedimenti_database" n
on esiste
First migration doesn't create the database, it needs existing database to create tables in it.
To create postgres database run from your terminal:
createdb -U postgres possedimenti_database
You might have to replace postgres in above command with your database user.
check the details in your settings.py for your DB. Recreate the PostgreSQL database using those exact same details (port number, user, host, password etc). Try this existing solution here link here:
PostgreSQL - create a new DB through pgAdmin UI in order to create the DB via pgAdmin