Local database throws an error after adding the managed database cluster on DO Apps

Posted December 24, 2020 1.4k views
PostgreSQLDatabasesBuilding on DigitalOcean

In our Django project that we are testing via DO Apps. I followed along with this tutorial

and added this block of code.

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

        "default": {
            "ENGINE": "Our local database postgres creds",
            "NAME": os.path.join(BASE_DIR, "postgres "),
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")),

In our environment variable at the app, we have set the Debug mode to True and DEVELOPMENT_MODE is also True.

The issue is that every time we try to run the local server. We see a cookie that is creating a session and crashing the site. We have to delete that cookie to run the local env and I am suspecting that this is caused by this block of code that I mentioned above. Is my assumption is correct and how can I fix this?

Second, what is the best practice to add the env variable for the dev branch that can work locally and also on digital ocean apps? I am thinking that on my local machine

Debug == TRUE

and the env variable at the DO app as.

Debug == False

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

I suspect your cookie issue is related to not setting a stable DJANGOSECRETKEY / SECRET_KEY value. lays out good practices for managing env vars. Be sure to add the .env file to the .gitignore to avoid committing anything sensitive to github.