python manage.py runserver won't run after git cloning my repo

Question:

I am having issues running python manage.py runserver after git cloning my project repo, creating a virtual environment and installing all required requirements.

(.venv) PS C:UsersASUSdesktopprojectfile-comp-107> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 244, in ensure_connection
    self.connect()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 225, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendspostgresqlbase.py", line 203, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagespsycopg2__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: fe_sendauth: no password supplied


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0libthreading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0libthreading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsautoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangocoremanagementcommandsrunserver.py", line 137, in inner_run
    self.check_migrations()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangocoremanagementbase.py", line 576, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbmigrationsexecutor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbmigrationsloader.py", line 58, in __init__
    self.build_graph()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbmigrationsloader.py", line 235, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbmigrationsrecorder.py", line 81, in applied_migrations
    if self.has_table():
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbmigrationsrecorder.py", line 57, in has_table
    with self.connection.cursor() as cursor:
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 284, in cursor
    return self._cursor()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 260, in _cursor
    self.ensure_connection()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 243, in ensure_connection
    with self.wrap_database_errors:
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbutils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 244, in ensure_connection
    self.connect()
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendsbasebase.py", line 225, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangoutilsasyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagesdjangodbbackendspostgresqlbase.py", line 203, in get_new_connection
    connection = Database.connect(**conn_params)
  File "C:UsersASUSdesktopprojectfile-comp-107.venvlibsite-packagespsycopg2__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: fe_sendauth: no password supplied
Asked By: Reloaded

||

Answers:

As the error returned is django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: fe_sendauth: no password supplied, I assume a environment variable which sets the DB password is missing.

Answered By: abwesend

It seems you have an error with your database connection. Use and replace the below code snippet with your own credentials in your settings.py file. Happy coding

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'YOUR_DATABASE_NAME',
        'USER': 'YOUR_DATABASE_USERNAME',
        'PASSWORD': 'YOUR_DATABASE_USERNAME',
        'HOST': 'localhost',
        'PORT': '5432',

        # Use the below Options when you have a Postgresql server with SSL.
        # 'OPTIONS': {
        #     'sslmode': 'require',
        # }
    }
}
Answered By: Maruf Khan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.