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

Hello! I'm having difficulties making the PostgreSQL to Postgres switch using Flask-SQLAlchemy. In my new project, I've already added the DATABASE_URL variable to connect to the database as it was previously. However, I'm encountering the following error: raise exc.NoSuchModuleError( sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres I don't know what to do. Here's my code: app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL') Project ID: 0efe927a-43aa-4eba-b481-0724b8ec2063
Solution:
in the database service edit the DATABASE_URL variable as replace postgres:// with postgresql://
Jump to solution
15 Replies
Percy
Percy8mo ago
Project ID: 0efe927a-43aa-4eba-b481-0724b8ec2063
Leonardo
Leonardo8mo ago
That file, correct?
Solution
Brody
Brody8mo ago
in the database service edit the DATABASE_URL variable as replace postgres:// with postgresql://
Brody
Brody8mo ago
then redeploy your flask service
Leonardo
Leonardo8mo ago
My god, yes, it seems that the error has stopped, you are a god. If you could help me with this last thing now, instead of running the server to open on Railway, it seems to be trying to run on localhost, my code: from sistemaLagoa import app if name == "main": app.run(debug=True) Below is the log file:
Brody
Brody8mo ago
send your main.py please
Leonardo
Leonardo8mo ago
My main.py file contains exactly: from sistemaLagoa import app if name == "main": app.run(debug=True) But the _ _init __.py file where I configure the application:
Brody
Brody8mo ago
thats not standard, so im not sure if this will work, add this as a railway.json file to your project
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"deploy": {
"startCommand": "gunicorn main:app"
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"deploy": {
"startCommand": "gunicorn main:app"
}
}
and make sure you have gunicorn in your requirements.txt
Leonardo
Leonardo8mo ago
Alright, in my project, there was already a file called Procfile that contained: web: gunicorn main:app Nevertheless, I added the railway.json as you suggested, but unfortunately, it crashed: /bin/bash: line 1: gunicorn: command not found (This line repeated 6 times).
Brody
Brody8mo ago
you need gunicorn in your requirements.txt you can also delete the Procfile
Leonardo
Leonardo8mo ago
It worked, thank you very much. I've saved your help in my favorites, and I'll return the favor as soon as I can. If I seemed rude in any way, I'm sorry, it was ChatGPT translating from Portuguese to English.
Brody
Brody8mo ago
not rude in anyway! ChatGPT did a pretty good job at translating!