Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"settings.DATABASES is improperly configured" error performing syncdb with django 1.4

I've created a simple django 1.4 project and am trying to issue syncdb to create the (postgres) db schema. I'm getting this error :-

Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 443, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 382, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 196, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 232, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 371, in handle return self.handle_noargs(**options) File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs cursor = connection.cursor() File "/usr/local/lib/python2.6/dist-packages/django/db/backends/dummy/base.py", line 15, in complain raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured.Please supply the ENGINE value. Check settings documentation for more details. 

My settings.py file looks like :-

DATABASES = {     'default': {         'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.         'NAME': 'test',                      # Or path to database file if using sqlite3.         'USER': 'test',                      # Not used with sqlite3.         'PASSWORD': 'test',                  # Not used with sqlite3.         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.         'PORT': '',                      # Set to empty string for default. Not used with sqlite3.      } } 

I can connect to the database using psql OK - any ideas ? Thanks in advance !

like image 427
bzo Avatar asked Apr 19 '12 12:04

bzo


2 Answers

It might be that django is not accessing the settings.py file you think it uses. Try explicitly point django to your settings file by using --settings

./manage.py --settings=nameofproject.settings runserver/syncdb 

If this works then, you'll have to figure out why django is importing the wrong settings file.

Have you upgraded from 1.3 to 1.4 by accident ?

like image 77
Jonas Geiregat Avatar answered Sep 17 '22 13:09

Jonas Geiregat


For me, I had a similar problem with django 1.6 just now:

BACKGROUND

Django 1.6 heroku project using Heroku Postgresql database

I wanted to develop directly on the postgresql server (so don't copy the ".postgresql_psycopg2" bit if you're not also using postgresql)

  • No problem developing using the local psql db
  • Got that error when I uncommented the line to use heroku db

    DATABASES['default'] =  dj_database_url.config(default=os.getenv('DATABASE_URL'))   

Initial attempt was to add more details, such as another line,

DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' 

This didn't work though, because then the error asked me for NAME, which it rejected.

SOLUTION

In the end, this solved it:

  1. I ran "heroku config" to see my details presented to me in the format:

    postgres://user:pass@localhost/dbname 
  2. I updated the settings.py file to reflect those details:

    DATABASES = {     'default': {         'ENGINE': 'django.db.backends.postgresql_psycopg2',          'NAME': 'your_heroku_db_name',                              'USER': 'your_heroku_db_user_name',         'PASSWORD': 'your_heroku_password',         'HOST': 'ec2-23-21-133-106.compute-1.amazonaws.com', # Or something like this         'PORT': '5432',                          } } 

    That tip is from https://stackoverflow.com/a/19719966/870121

    Note: my next plan is to abstract these back into .env variables rather than leaving them visible in settings.py

  3. I then commented out the later line,

    # DATABASES['default'] =  dj_database_url.config(default=os.getenv('DATABASE_URL'))   

    so DATABASES was only specified once in the settings.py file

    That way the program read everything required to connect to the postgresql heroku db

    e.g., now python manage.py syncdb is working for me


If you want to try developing locally, comment out everything above and instead set your local postgresql server going and uncomment the local equivalent of the above:

DATABASES = {      'default': {          'ENGINE': 'django.db.backends.postgresql_psycopg2',          'NAME': 'cool01db',          'USER': '',           'PASSWORD': '',          'HOST': 'localhost', # '127.0.0.1' probably works also          'PORT': '5432',      }  } 

That's from https://stackoverflow.com/a/25962586/870121

like image 23
Mark Avatar answered Sep 17 '22 13:09

Mark