. Advertisement .
..3..
. Advertisement .
..4..
Hi developer experts, I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command and facing one problem with the can’t load plugin sqlalchemy dialects postgres. Below is the command I used:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://username@localhost:5432/template1"
db = SQLAlchemy(app)
When I run it, I get the following error:
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres
I am looking forward to gaining some knowledge from all experts. Thank you, guys!
The cause:
This error happened because when working with Heroku, you used
postgres
in theDATABASE_URL
which they gave, but SQLAlchemy 1.4 deleted the requiredpostgres
dialect name.Solution:
To solve this error, you have to replace
postgres://
bypostgresql://
in the URL and change the variable in the Heroku dashboard topostgresql
.The part before the
://
in the URL is dialect. SQLAlchemy 1.3 earlier gave a deprecation warning but it was still accepted.Another way to fix this error is using python url to replace code in heroku as below:
Let’s read this article to have more information: https://help.heroku.com/ZKNTJQSK/why-is-sqlalchemy-1-4-x-not-connecting-to-heroku-postgres
postgresql://
should be used as the URI instead ofpostgres://
. SQLAlchemy used both but no longer acceptspostgres
.