Django error in Heroku: “Please supply the ENGINE value”

前端 未结 6 744
广开言路
广开言路 2021-01-04 20:14

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

raise ImproperlyConfigured(\"settings.DATABASES is         


        
相关标签:
6条回答
  • 2021-01-04 20:46

    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
    
    0 讨论(0)
  • 2021-01-04 20:46

    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.

    0 讨论(0)
  • 2021-01-04 20:54

    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.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-04 21:07

    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.

    0 讨论(0)
  • 2021-01-04 21:10

    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
    
    0 讨论(0)
提交回复
热议问题