Reputation: 629
I have this setting on a fastAPI small application:
host_server = os.environ.get('host_server', 'localhost')
db_server_port = urllib.parse.quote_plus(str(os.environ.get('db_server_port', '5432')))
database_name = os.environ.get('database_name', 'mydatabasename123')
db_username = urllib.parse.quote_plus(str(os.environ.get('db_username', 'myusername123')))
db_password = urllib.parse.quote_plus(str(os.environ.get('db_password', 'mypassword123')))
ssl_mode = urllib.parse.quote_plus(str(os.environ.get('ssl_mode', 'prefer')))
DATABASE_URL = 'postgresql://{}:{}@{}:{}/{}?sslmode={}'.format(db_username, db_password, host_server, db_server_port,
database_name, ssl_mode)
database = databases.Database(DATABASE_URL)
locally it works, but when I try to deploy it to heroku, I change some things. I am use the DATABASE_URL env variable provided on Heroku:
DATABASE_URL = 'postgres://...'
database = databases.Database(DATABASE_URL)
or doing
DATABASE_URL = os.environ.get('DATABASE_URL')
database = databases.Database(DATABASE_URL)
metadata = sqlalchemy.MetaData()
engine = sqlalchemy.create_engine(
DATABASE_URL, pool_size=3, max_overflow=0, echo=True
)
logs give me:
: at=error code=H10 desc="App crashed" method=GET path="/"
Upvotes: 0
Views: 422
Reputation: 55589
"postgres" is no longer accepted as a dialect name in SQLAlchemy. The correct form is "postgresql", as you are using locally:
DATABASE_URL = 'postgresql://...'
Using 'postgres://...'
raises
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'postgres//...'
This change was introduced in SQLAlchemy 1.4.0b1
Upvotes: 3