Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku using postgres:// instead of postgresql:// in DATABASE_URL

I am able to successfully deploy my Flask app on Heroku, but I'm not able to connect to my database (Internal Server Error). I noticed that the connection string in the Heroku DATABASE_URL begins with postgres:// instead of the usual postgresql://. I am able to connect to the Heroku database when I run my app locally using the connection string postgresql://[etc.] but not with postgres://[etc.]. Does anyone know how I can fix this? Heroku doesn't allow editing the DATABASE_URL environment variable. I've been pounding my head against the desk for hours and I'm about to give up.

Thank you.

like image 870
dkstenor Avatar asked Oct 21 '25 12:10

dkstenor


1 Answers

Do edit your connection string like this in python. I am using slicing. You can use similar approach in other language.

DATABASE_URI = os.environ['DATABASE_URL']

DATABASE_URI= DATABASE_URI[:8]+'ql' + DATABASE_URI[8:]

Essentially what it does is take the first 8 characters, adds 'ql' and then adds the remaining characters and replaces the string.

like image 69
Anikash Chakraborty Avatar answered Oct 24 '25 04:10

Anikash Chakraborty