Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

I'm trying to connect to a Postgres database with SQLAlchemy. I've installed psycopg2. However, I get the error sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres. How do I configure SQLAlchemy to connect to PostgreSQL?

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) 
like image 551
Maharsh Gheewala Avatar asked Jul 02 '20 02:07

Maharsh Gheewala


1 Answers

The URI should start with postgresql:// instead of postgres://. SQLAlchemy used to accept both, but has removed support for the postgres name.

like image 89
Leandro Lima Avatar answered Sep 21 '22 14:09

Leandro Lima