Beginner
Beginner

Reputation: 749

Getting Database is improperly configured .Please supply the name value error

I come across this question settings.DATABASES is improperly configured. Please supply the NAME value but it doesn't worked for me.


On applying python manage.py makemigrations,I am getting the error

Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in  execute_from_command_line
utility.execute()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 106, in handle
loader.check_consistent_history(connection)
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 276, in check_consistent_history
applied = recorder.applied_migrations()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 233, in cursor
cursor = self.make_cursor(self._cursor())
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 170, in connect
conn_params = self.get_connection_params()
File "/home/rishav/EvalAI/venv/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 158, in get_connection_params
"settings.DATABASES is improperly configured. "
 django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.

My dev database

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'evalai',
    'USER': 'rishav',
    'PASSWORD': 'rishav',
    'HOST': 'localhost',
    'PORT': 5432,
  }
 }

And the prod database

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': os.environ.get('RDS_DB_NAME', ""),
    'USER': os.environ.get('RDS_USERNAME', ""),
    'PASSWORD': os.environ.get('RDS_PASSWORD', ""),
    'HOST': os.environ.get('RDS_HOSTNAME', ""),
    'PORT': os.environ.get('RDS_PORT', ""),
  }
}

How to fix this?

Upvotes: 1

Views: 2845

Answers (1)

rdegges
rdegges

Reputation: 33824

It sounds like your environment variable(s) in production may not be set -- I suspect this is what's happening.

Log into your production server(s) and ensure that your Django process has access to RDS_DB_NAME, RDS_USERNAME, etc. as environment variables.

ALSO: If you're having problems, you might want to try hard-coding fake credentials instead of using environment variables. This will at least get you to the next error, which should say invalid credentials or something similar. This will confirm that environment variables are the issue and need to be fixed.

UPDATE: If you want to try hardcoding credentials, do something like this for your production database config:

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'test',
    'USER': 'test',
    'PASSWORD': 'test',
    'HOST': 'localhost',
    'PORT': 5432,
  }
}

This will 'hardcode' your fake credentials. You can then deploy this application and see what error you're getting.

Upvotes: 1

Related Questions