1

When I change my setting of Database according to the official guide as DATABASES['default'] = dj_database_url.config() It has NameError: name 'DATABASES' is not defined when building.

When I change the syntax of database settings to DATABASES = { 'default': dj_database_url.config() }, it has settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. when opening the app locally. and it has Internal Server Error: The server encountered an unexpected internal server error (generated by waitress) when launching from heroku.

Notice, this way worked once. But when i merge my code with my friends, it has problem again. I roughly located it was database problem. So i delete the database on heroku and wanted to sync again. But when I sync the database, it has Import error: No module named events.

When I change the setting back to the original way: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(PROJECT_PATH, 'db.sqlite3'), } } It can work locally(of course), but can't in the heroku, with the error of Import error: No module named events too when syncing the database.

PS: 1, I made sure that Heroku installed all the requirements I need to run the app, especially i triple checked all the files: models, views, urls, etc. 2, I use waitress as the server instead of gunicorn recommended by the Heroku official guide.

How can I fix it?

1 Answer 1

1

You need a DATABASE_URL environment variable that dj_database_url will read.

To set it, run heroku config: set DATABASE_URL=<your database url> from your terminal.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! but what is my database url? sqlite3? and I'll write DATABASES = {'default': dj_database_url.config()} in the setting right?
You shouldn't need to do this, as Heroku should set it automatically. Go to the environment settings in the dashboard and check there is one for the database url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.