From c38155e355fe72a74c923506b5b1850a10b60fb3 Mon Sep 17 00:00:00 2001 From: Paras Gupta Date: Sun, 29 Aug 2021 20:04:09 +0530 Subject: [PATCH 1/2] Update postgres DATABASE_URL as per psycopg2 requirements. --- app.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 4084c0a..2d58997 100644 --- a/app.py +++ b/app.py @@ -15,9 +15,11 @@ # "sqlite:///data.sqlite" # /// for relative path # //// for absolute path -app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( - "DATABASE_URL", "sqlite:///data.sqlite" -) + +DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///data.sqlite") +DATABASE_URL.replace("postgres://", "postgresql://", 1) + +app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "thisissecret") app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(hours=12) From bdcc376261466391e0c624e3b55c59a090cbc2e6 Mon Sep 17 00:00:00 2001 From: Paras Gupta Date: Sun, 29 Aug 2021 20:20:06 +0530 Subject: [PATCH 2/2] Assign updated database_url to the same. replace method does not update the string instead, it creates a new string. We need assing that new string to database_url --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 2d58997..4d59b17 100644 --- a/app.py +++ b/app.py @@ -17,7 +17,7 @@ # //// for absolute path DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///data.sqlite") -DATABASE_URL.replace("postgres://", "postgresql://", 1) +DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1) app.config["SQLALCHEMY_DATABASE_URI"] = DATABASE_URL app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False