- SQLAlchemy (especially when using the
psycopg2
driver for PostgreSQL) requires the URI to be in the format postgresql+psycopg2://
. - This prefix specifies the dialect (
postgresql
) and the driver (psycopg2
) explicitly, which SQLAlchemy uses to establish the connection.
Heroku's DATABASE_URL
uses the older postgres://
scheme, which isn't compatible with the latest SQLAlchemy requirements. Starting with SQLAlchemy 1.4, postgres://
is considered deprecated and no longer supported. The explicit postgresql+psycopg2://
scheme is required.