Asked  10 Months ago    Answers:  5   Viewed   5 times

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 "", line 10, in <module>
File "/usr/local/lib/python2.6/dist-packages/django/core/management/", line 443, in execute_from_command_line
File "/usr/local/lib/python2.6/dist-packages/django/core/management/", line 382, in execute
File "/usr/local/lib/python2.6/dist-packages/django/core/management/", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/", line 57, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/dummy/", 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 file looks like :-

    '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 !



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

./ --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 ?

Sunday, August 1, 2021

You can't just fire up Python and check things, Django doesn't know what project you want to work on. You have to do one of these things:

  • Use python shell
  • Use shell --settings=mysite.settings (or whatever settings module you use)
  • Set DJANGO_SETTINGS_MODULE environment variable in your OS to mysite.settings
  • (This is removed in Django 1.6) Use setup_environ in the python interpreter:

    from import setup_environ
    from mysite import settings

Naturally, the first way is the easiest.

Monday, June 7, 2021

You are using the dj-database-url module to set DATABASES['default']. Whatever comes before the line:

DATABASES['default'] =  dj_database_url.config()

is meaningless as you replace your database configuration in its entirety. The dj_database_url.config() loads your database configuration from the DATABASE_URL environment variable, or returns {} if the variable is not set.

Judging by your error, you didn't set the DATABASE_URL at all. Judging by the code preceding the dj_database_url.config() line, you should not be using the dj_database_url.config() function at all.

If you did want to use it, at least build a default URL:

    DATABASE_URL = 'postgresql://<postgresql>'
    DATABASE_URL = 'sqlite:///' + os.path.join(BASE_DIR, 'db.sqlite3')

DATABASES = {'default': dj_database_url.config(default=DATABASE_URL)}
Sunday, September 19, 2021

Did you try the stuff in the documentation at

import dj_database_url
DATABASES['default'] =  dj_database_url.config()

It says

Django settings

Next, configure the application for the Heroku environment, including Heroku’s Postgres database. The dj-database-url module will parse the values of the DATABASE_URL environment variable and convert them to something Django can understand.

Make sure ‘dj-database-url’ is in your requirements file, then add the following to the bottom of your file:

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =  dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()

# Allow all host headers

# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'

    os.path.join(BASE_DIR, 'static'),
Thursday, November 18, 2021

Django Admin groups Models to admin block by their apps which is defined by Model._meta.app_label. Thus registering Review in followers/ still gets it to app review.

So make a proxy model of Review and put it in the 'review' app

class ProxyReview(Review):
    class Meta:
        proxy = True    
        # If you're define ProxyReview inside review/,
        #  its app_label is set to 'review' automatically.
        # Or else comment out following line to specify it explicitly               
        # app_label = 'review'

        # set following lines to display ProxyReview as Review
        # verbose_name = Review._meta.verbose_name
        # verbose_name_plural = Review._meta.verbose_name_plural

# in

Also, you could put Followers and Review to same app or set same app_label for them.

Customize admin view or use 3rd-part dashboard may achieve the goal also.

Saturday, September 25, 2021

The closest I got to this was based on another stackoverflow article here: How to have 2 different admin sites in a Django project?

I ended up creating two entirely separate instances of django.contrib.admin.sites.AdminSite which seemed to work in the end, albeit not ideal.

Thursday, September 30, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :