How to solve dj_database_url error

Posted February 17, 2021 2.4k views
PythonDjangoPython FrameworksDevelopmentDigitalOcean App Platform


I have been following the ‘How to Deploy a Django App on App Platform’ tutorial and I keep getting the following error during deploy:

File "/workspace/.heroku/python/lib/python3.8/site-packages/", line 103, in parse
engine = SCHEMES[url.scheme] if engine is None else engine
KeyError: ''

[11] [INFO] Worker exiting (pid: 11)
[1] [INFO] Shutting down: Master
[INFO] Reason: Worker failed to boot.

The configuration regarding the database in is identical to the one used in the tutorial:

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

        "default": {
            "ENGINE": "django.db.backends.sqlite3",
            "NAME": os.path.join(BASE_DIR, "db.sqlite3"),
elif len(sys.argv) > 0 and sys.argv[1] != 'collectstatic':
    if os.getenv("DATABASE_URL", None) is None:
        raise Exception("DATABASE_URL environment variable not defined")
        "default": dj_database_url.parse(os.environ.get("DATABASE_URL")),

Any clue on this?

Thanks a lot.

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.

Submit an Answer
1 answer

It looks like your DATABASEURL env variable isn’t populated. App Platform will automatically set DATABASEURL when you add a database component. You can add the component by going to the Components tab of your app, and then clicking + Create Component, then Database. You should be able to add either a new development database or an existing managed database. If you’re using a database not provided through DigitalOcean’s managed databases, you’ll have to set the DATABASE_URL manually.

If you’re still seeing problems, please reach out to support.