database - Django. South. Heroku. KeyError: 'default' -


i'm new heroku, tried following instructions literally , i'm lost error. so, when included settings.py configurations written in "getting started django on heroku" can't run local server anymore unless comment out south installed apps.

this error:

 south.db import default_db_alias  file "/home/alejandro/proyectos/olenv/local/lib/python2.7/site-packages/south/db/__init__.py", line 83, in <module>  db = dbs[default_db_alias]  keyerror: 'default' 

this relevant settings in settings.py:

databases = { 'default': {     'engine': 'django.db.backends.postgresql_psycopg2',     'name': 'dbolib',     'user': 'alejandro',     'password': 'zzzzz' } }   # --- heroku --- #  # parse database configuration $database_url  import dj_database_url  databases['default'] = dj_database_url.config() 

maybe supposed way since south tool production , therefore conflicts heroku. maybe not, since im new heroku, clarification help.

edit when comment out south , try run syncdb, ge error:

file "/home/alejandro/proyectos/olenv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain raise improperlyconfigured("settings.databases improperly configured. " django.core.exceptions.improperlyconfigured: settings.databases improperly configured. please supply engine value. check settings documentation more details. 

requirements.txt:

django==1.6 south==0.8.4 argparse==1.2.1 dj-database-url==0.3.0 dj-static==0.0.5 django-crispy-forms==1.4.0 django-debug-toolbar==1.2 django-endless-pagination==2.0 django-extensions==1.3.5 django-toolbelt==0.0.1 gunicorn==18.0 psycopg2==2.5.2 pystache==0.5.4 six==1.6.1 sqlparse==0.1.11 static==1.0.2 wsgiref==0.1.2 

when comment out south in installed_apps, let run python manage.py syncdb locally?

i think problem you're overwriting default database dj_database_url lines in settings.py. when you're on heroku, there's environment variable named database_url, dj_database_url uses config database. however, if don't have similar environment variable locally, won't configuring database correctly. reason south throwing error because tries connect database upon initialization (note how error comes south's __init__). if tried use database locally after commenting out south, i'm guessing you'd error.

there 2 ways fix this. first, , easiest, make database_url variable on local machine. given settings listed above, set database_url 'postgres://alejandro:zzzzz@localhost/dbolib'. second, , more difficult, add in settings check if you're on heroku and, if not, skip on dj_database_url configuration. basically, nest dj_database_url lines in settings inside if statement return true if on heroku , false if not.

edit:

it gets little messy, if want keep in 1 file, following:

first, try set default database using dj_database_url. means moving following code above databases setting in settings:

import dj_database_url databases = {} databases['default'] = dj_database_url.config() 

this code sets default database equal result dj_database_url. however, there may not result. you'll want test (which indicate local development) , set database accordingly. so, after previous code, add following code:

if len(databases['default']) == 0:     databases = {         'default': {             'engine': 'django.db.backends.postgresql_psycopg2',             'name': 'dbolib',             'user': 'alejandro',             'password': 'zzzzz'     } } 

this checks see if have in databases['default'] and, if not, sets default database using local settings.

this little messy, it'll work. better option may use different settings files, adds layer of complexity. truly, best option set database_url environment variable on of machines dj_database_url works should.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -