10

I read and apply "Getting started with Django on Heroku" tutorial but ran into problem while syncing db:

raise ImproperlyConfigured("settings.DATABASES is improperly configured." 
django.core.exceptions.ImproperlyConfigured: 
settings.DATABASES is improperly configured. Please supply the ENGINE value. 

I read Please supply the ENGINE value Django database configuration and “settings.DATABASES is improperly configured” error performing syncdb with django 1.4 but still receive same error. While executing

heroku run python manage.py --settings=moz455.settings syncdb

I receive error "Unknown command: '--settings=moz455.settings'". How to solve this problem?

Version of Django is 1.4.

Community
  • 1
  • 1
DSblizzard
  • 4,007
  • 7
  • 48
  • 76
  • The issue is that although the "[Getting Started with Django on Heroku](https://devcenter.heroku.com/articles/django)" tutorial makes you install and use the "dj-database-url" package, it only mentions in passing that settings.DATABASES will be configured from the DATABASE_URL env variable. See [Configuration and Config Vars](https://devcenter.heroku.com/articles/config-vars); to use the database that Heroku sets up, see the [Using Foreman and heroku-config](https://devcenter.heroku.com/articles/config-vars#using-foreman-and-herokuconfig) paragraph (especially the `heroku config:pull` bit). – Greg Sadetsky Nov 09 '12 at 03:09

6 Answers6

12

I ran into the same issue, but apparently for different reasons. In the Heroku docs at https://devcenter.heroku.com/articles/django#prerequisites, it says to add the following to settings.py:

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

You can pass in a parameter of:

DATABASES['default'] =  dj_database_url.config(default='postgres://user:pass@localhost/dbname')

And that will allow you to develop locally and on Heroku. The part that actually SOLVES the problem I had though was that the Heroku config environment variable of DATABASE_URL was not actually set. To set this, I ran

$ heroku config

I saw the Database URL assigned to a separate config variable. So I created a new variable:

$ heroko config:add DATABASE_URL={#the database url}

That solved my problem. I hope it helps anyone else with similar issues.

sethammons
  • 743
  • 6
  • 10
8

After trying all the answers here and verifying DATABASE_URL exists, nothing worked.

I added the second line and it worked

DATABASES['default'] = dj_database_url.config() <--- heroko docs says this is enough
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' <---- add this
Or Arbel
  • 2,965
  • 2
  • 30
  • 40
  • This is all I had to do. I wonder if this is a necessary change for Django 1.5; I didn't have to do it previously. I also had to prefix both of these lines with `DATABASES = {}` – Seth Aug 21 '13 at 16:18
  • 1
    After I do this I get a new error: asking me to supply NAME. It's as if dj_database_url.config() is not supplying the needful... – GreenAsJade Aug 13 '14 at 12:16
  • @GreenAsJade I had the same problem! Did you solve it? – Hadi Jul 31 '15 at 16:37
  • 1
    @Constantine it was a while ago now, but best I can recall, I had confusion over what was reading what: there are so many ways of starting django up, and they seemed to have different effects. I now how that line in my config, and start with foreman, and it works. I have a comment that says "#if foreman is not reading the .env file #DATABASES['default'] = dj_database_url.config(default = 'postgres://user:@localhost/user')" HTH – GreenAsJade Aug 02 '15 at 00:05
3

Ensure that you have the database add-on installed and setup properly. See https://devcenter.heroku.com/articles/database#no-dev-database-or-no-database-url

I ran the following to fix the issue:

heroku addons:add heroku-postgresql
heroku pg:promote HEROKU_POSTGRESQL_CYAN
John Slade
  • 12,246
  • 2
  • 25
  • 20
  • 1
    The `pg:promote` line might have a different color on the end - mine was `ORANGE`, I've seen `RED` too. – Kyle Feb 16 '13 at 21:26
1

Solved it myself: in manage.py add code similar to this:

CurDir = os.path.dirname(os.path.abspath(__file__))
ProjectDir = os.path.join(CurDir, "moz455")
sys.path += [ProjectDir]

And commit changes with these commands:

git add -A
git commit -m "commit"
git push -f heroku
DSblizzard
  • 4,007
  • 7
  • 48
  • 76
0

Try different order:

heroku run python manage.py syncdb --settings=moz455.settings

The manage.py command looks like this:

manage.py <command> <options>

but you used it like this:

manage.py <options> <command>

Your other problem (lack of ENGINE setting) may be caused by incorrect settings file being used during the syncdb command execution. The above should fix it also.

Tadeck
  • 132,510
  • 28
  • 152
  • 198
  • No, second (main) problem remains. Django doesn't see settings.py. On local computer I add this to manage.py: sys.path += ["D:/blizzard/Projects/Python/Web/moz455/moz455"], but what is the project dir on Heroku? And is it the right way? – DSblizzard Aug 06 '12 at 11:08
  • @DSblizzard: Did you follow the guide from Heroku (https://devcenter.heroku.com/articles/django#database-settings)? They have [up-to-date guide for deploying Django apps](https://devcenter.heroku.com/articles/django). – Tadeck Aug 06 '12 at 13:12
0

it is a little late ; but you just delete all default django database settings lines ; and add heroku's one.

it will work correctly

** edit ** or simply you can use `socket.gethostname().

example :

if socket.gethostname() == 'xx':
    DATABASE_SETTINGS ={ }

elif socket.gethostname() == 'xxx':
    another database settings...

so you can run your project under multiple hosts.

alioguzhan
  • 7,657
  • 10
  • 46
  • 67