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)
The URI should start with postgresql://
instead of postgres://
. SQLAlchemy used to accept both, but has removed support for the postgres
name.