Learn Flask>Deploying a Flask App [SQLAlchemy app config issue]

Summary of the report:
When trying to run our app on Heroku we get an error which says at the bottom of the error log " Flask and Heroku sqlalchemy.exc.NoSuchModuleError: Can’t load plugin: sqlalchemy.dialects:postgres". This occurs because in a later version of postgresql they changed the URI name from postgres to postgresql.
Course URL:
Learn Flask | Codecademy
Steps to Reproduce:
Follow the instructions in the article.
Fix or Workaround:
I got the fix from this stackoverflow topic: python - Flask and Heroku sqlalchemy.exc.NoSuchModuleError: Can’t load plugin: sqlalchemy.dialects:postgres - Stack Overflow. The line

app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('DATABASE_URL') or 'sqlite:///myDB.db'

needs to be changed to

app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('DATABASE_URL').replace("://", "ql://", 1) or 'sqlite:///myDB.db'

Another workaround, which may be more professional than the former, would be to go to the SETTINGS tab of the Heroku app dashboard and change postgres to postgresql in the Config Vars.

1 Like

Good catch. It looks like that postgres:// was removed November 2, 2020 so shortly after this course was released if memory serves (though I could be off by a few months in either direction – hard to keep track of all the new Codecademy material lately)