Fix FastAPI + Celery deployment error on Railway

meellc
HOBBY

3 days ago

Hey all! I'm deploying a FastAPI + Celery backend on Railway. The app tries to connect to the database using await database.connect() inside my lifespan function, but I'm getting this error:

NameError: name 'database' is not defined

I do have a DATABASE_URL set in my environment variables, and I'm using the databases library with asyncpg.

Any idea what I might be missing, or how I should properly structure this? Thanks!

$10 Bounty

1 Replies

meellc
HOBBY

3 days ago

7cf1d20e-b77e-42d1-b4c7-c5ec19f3f8e8


clashing
FREETop 1% Contributor

2 days ago

How are you defining the database variable in your code, please provide that code snippet