R
Railway13mo ago
Leonardo

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
Percy13mo ago
Project ID: 0efe927a-43aa-4eba-b481-0724b8ec2063
Leonardo
LeonardoOP13mo ago
That file, correct?
Solution
Brody
Brody13mo ago
in the database service edit the DATABASE_URL variable as replace postgres:// with postgresql://
Brody
Brody13mo ago
then redeploy your flask service
Leonardo
LeonardoOP13mo 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
Brody13mo ago
send your main.py please
Leonardo
LeonardoOP13mo 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:
Leonardo
LeonardoOP13mo ago
Brody
Brody13mo 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
LeonardoOP13mo 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
Brody13mo ago
you need gunicorn in your requirements.txt you can also delete the Procfile
Leonardo
LeonardoOP13mo 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
Brody13mo ago
not rude in anyway! ChatGPT did a pretty good job at translating!
Want results from more Discord servers?
Add your server