Application Crashes on Deployment - ModuleNotFoundError for MySQLdb
antonioc-cl
PROOP

10 months ago

I am facing an issue when deploying my Flask application on Railway. The app fails to start, and I receive the following error:

The full stack trace shows that SQLAlchemy is trying to use the MySQLdb driver, despite having PyMySQL installed and specified in my requirements.txt.

Environment Setup

  • Tech stack:

  • Flask (version: 2.3.3)

  • Flask-SQLAlchemy (version: 3.1.1)

  • Gunicorn (version: 23.0.0)

  • PyMySQL (version: 1.1.0)

  • SQLAlchemy (version: 2.0.37)

  • Project structure:

  • Current DATABASE_URL: The environment variable DATABASE_URL is set in Railway's settings but does not specify the pymysql driver.

Steps Taken to Fix

  1. Updated `DATABASE_URL

  2. Verified that PyMySQL is installed via requirements.txt.

  3. Updated the Gunicorn command in the custom start command:

  1. Tested locally, and the app works without issues.

Could you confirm whether Railway supports mysql+pymysql?
Is there anything else I need to configure in the deployment process to resolve this issue?
Any suggestions for further debugging?

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

Solved

2 Replies

brody
EMPLOYEE

10 months ago

Hello,

You have PyMySQL in your requirements.txt file, but you aren't using it anywhere in your code, instead you are using SQLAlchemy

Please make sure you are using only PyMySQL in your code.


antonioc-cl
PROOP

10 months ago

Thanks for your help as always, Brody.


Status changed to Solved brody 10 months ago


Loading...