Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Heroku and your local machine usually need different database settings. A common way to handle that is to first list your local database settings in the settings.py file, then do a check to see if you're code is currently running on Heroku, and if so, override your database settings with what Heroku needs. That allows a single settings.py file to work in both environments.</p> <p>Heroku creates an environment variable called DATABASE_URL containing the database URL string. A common way to check whether your code is running on Heroku is to check for that environment variable. Then, if it exists, use the dj_database_url module, which knows how to parse that string into the dictionary that Django needs for its configuration.</p> <p>The only thing incorrect in your code is that you didn't check for the environment variable first before calling dj_database_url.config(). This means that dj_database_url, which normally should only run within Heroku, was running on your local machine too. Since your local machine almost certainly doesn't have the DATABASE_URL environment variable set, dj_database_url returned an empty dictionary. So, your code is overwriting your local database configuration with an empty dictionary when it's not run on Heroku. Django looks in that dictionary for the information it needs, can't find it, and raises an error.</p> <p>To fix the problem, add a check for DATABASE_URL before using dj_database_url.</p> <p>Change this part at the end of settings.py:</p> <pre><code>import dj_database_url DATABASES['default'] = dj_database_url.config() </code></pre> <p>To this:</p> <pre><code>if os.environ.get('DATABASE_URL', None): import dj_database_url DATABASES['default'] = dj_database_url.config() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload