Exception("DATABASE_URL environment variable not defined") When running local server

I built a django app on my local machine, and then used this tutorial to deploy it with app platform ( The deployment was successful.

However, now when I try to run my django app locally to continue development, I’m getting the following error:

…/", line 95, in <module> raise Exception(“DATABASE_URL environment variable not defined”) Exception: DATABASE_URL environment variable not defined

Current settings in DEVELOPMENT_MODE = os.getenv(“DEVELOPMENT_MODE”, “False”) == “True”

DEBUG = os.getenv(“DEBUG”, “False”) == “True”

I am unsure of how to reset my file so that it points to a local sqlite3 db for development.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
December 16, 2022

👋 @43e88fede83e446f9e392debd41d3c

Giving that tutorial a quick read over, it looks like you’ll need to set an environment variable to indicate that you’re in a development environment.

So in your dev env, set DEVELOPMENT_MODE=true.

This way the code will use a sqlite db instead of looking for a postgres instance, snippet from the tutorial:

        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "db.sqlite3"),

The dev env defaults to being disabled just above the snippet above:

# Database
DEVELOPMENT_MODE = os.getenv("DEVELOPMENT_MODE", "False") == "True"

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel