Reputation: 1626
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 !
Upvotes: 40
Views: 81748
Reputation: 1295
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)
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:
I ran "heroku config" to see my details presented to me in the format:
postgres://user:pass@localhost/dbname
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
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
Upvotes: 17
Reputation: 111
Re-installing Django did the trick for me(actually removing the egg file),as suggested in the following link. https://code.djangoproject.com/ticket/18058 It seems that upgrading from 1.3 to 1.4 seems to cause a lot of these problems.
Upvotes: 0
Reputation: 61
There are two 'settings.py' files in your project(if your OS is UNIX-like):
You need to write the ENGINE to the second (dir/dir/setting.py
).
Good luck!
Upvotes: 6
Reputation: 26096
Which settings.py file have you updated? I had this exact same problem at first too when I didn't read about Django's changes from 1.3 to 1.4 which causes double imports. Here is an excerpt from https://docs.djangoproject.com/en/1.4/releases/1.4/#updated-default-project-layout-and-manage-py. The latest version of Django (currently 1.4.2) ships with an updated default project layout and manage.py file for the startproject management command and the default project layout has changed.
To fix your error, the correct settings.py file you should use is NOT the one in the main project directory, it is the one inside the directory that is created inside the project directory (with the same name).
Upvotes: 3
Reputation: 5432
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 ?
Upvotes: 30