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

 Answers

2

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 ?

Sunday, August 1, 2021
 
Cam1989
 
3

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 manage.py shell
  • Use django-admin.py 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 django.core.management import setup_environ
    from mysite import settings
    
    setup_environ(settings)
    

Naturally, the first way is the easiest.

Monday, June 7, 2021
 
VieStar
 
4

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:

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

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

Did you try the stuff in the documentation at https://devcenter.heroku.com/articles/django#django-settings?

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 settings.py file:

settings.py

# 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()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

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

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

Django Admin groups Models to admin block by their apps which is defined by Model._meta.app_label. Thus registering Review in followers/admin.py 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/models.py,
        #  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 admin.py
admin.site.register(ProxyReview)

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
 
Jubair
 
3

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
 
max_
 
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 :  
Share