0

I was working on a login page and it worked, abandoned the project for a couple of months and when I got back to it I was getting this error:

settings.DATABASES is improperly configured. Please supply the NAME value.

Full Traceback

Traceback (most recent call last):
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\admin\sites.py", line 410, in login
    return LoginView.as_view(**defaults)(request)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\views.py", line 63, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\edit.py", line 141, in post
    if form.is_valid():
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 177, in is_valid
    return self.is_bound and not self.errors
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 172, in errors
    self.full_clean()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 375, in full_clean
    self._clean_form()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\forms\forms.py", line 402, in _clean_form
    cleaned_data = self.clean()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\forms.py", line 215, in clean
    self.user_cache = authenticate(self.request, username=username, password=password)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\__init__.py", line 73, in authenticate
    user = backend.authenticate(request, **credentials)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\backends.py", line 42, in authenticate
    user = UserModel._default_manager.get_by_natural_key(username)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\contrib\auth\base_user.py", line 45, in get_by_natural_key
    return self.get(**{self.model.USERNAME_FIELD: username})
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 425, in get
    num = len(clone)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 269, in __len__
    self._fetch_all()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 1308, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\sql\compiler.py", line 1154, in execute_sql
    cursor = self.connection.cursor()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
    return self._cursor()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
    self.ensure_connection()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
    self.connect()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\base\base.py", line 199, in connect
    conn_params = self.get_connection_params()
  File "C:\Users\Zeyad\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\postgresql\base.py", line 157, in get_connection_params
    raise ImproperlyConfigured(

Exception Type: ImproperlyConfigured at /admin/login/
Exception Value: settings.DATABASES is improperly configured. Please supply the NAME value.

I'm not sure what's the issue with the database code so here it is:

POSTGRES_HOST = os.environ.get('POSTGRES_HOST', default="")
POSTGRES_DB = os.environ.get('POSTGRES_DB', default="")
POSTGRES_USER = os.environ.get('POSTGRES_USER', default="")
POSTGRES_PASSWORD = os.environ.get('POSTGRES_PASSWORD', default="")


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': POSTGRES_DB,
        'USER': POSTGRES_USER,
        'PASSWORD': POSTGRES_PASSWORD,
        'HOST': POSTGRES_HOST,
        'PORT': 5432, 
    }
}

I've been looking for solutions for over 2 hours now and I haven't found anything since I already provided a name, would appreciate someone correcting me where I was wrong

  • Possible solutions: https://stackoverflow.com/questions/29811971/settings-databases-is-improperly-configured-please-supply-the-name-value and https://stackoverflow.com/questions/41725765/getting-database-is-improperly-configured-please-supply-the-name-value-error and https://stackoverflow.com/questions/26080303/improperlyconfigured-settings-databases-is-improperly-configured-please-supply – Rivers May 01 '21 at 12:28

1 Answers1

0

The error says you haven't set the NAME value for the database. Looking at your settings you do have

'NAME': POSTGRES_DB

And POSTGRES_DB is defined as

POSTGRES_DB = os.environ.get('POSTGRES_DB', default="")

So the most likely problem is that you haven't set the POSTGRES_DB environment variable. This fits your story of the project working before and not working when you came back to it. You are running the project in a different environment. You need to make sure you set all the necessary environment variables.

Brad Martsberger
  • 1,747
  • 13
  • 7
  • I'm not sure I know how to do that, any links or references to help me out? – zeyaddh May 01 '21 at 19:24
  • what OS are you on? – jsonderulo May 01 '21 at 21:09
  • My Os is Windows 20H2 – zeyaddh May 02 '21 at 04:58
  • I don't know a whole lot about windows, but here is an article about environment variables on windows. https://phoenixnap.com/kb/windows-set-environment-variable Here's a blog that recommends not using the OS environment variables https://alicecampkin.medium.com/how-to-set-up-environment-variables-in-django-f3c4db78c55f – Brad Martsberger May 02 '21 at 13:48