I have a Django project running smoothly, but when it needs to access the database specificaly in production (Vercel serverless function) it can’t connect:
connection to server at "db.XXXXXXX.supabase.co" (2600:1f18:2e13:9d0a:17a3:b94b:5d9:cf52), port 5432 failed: Cannot assign requested address
Is the server running on that host and accepting TCP/IP connections?
I can connect to the database locally, it only occurs in Vercel. I quadra-checked the environment variables.
Code is here, i reproduced the error in this public project to facilitate. Anyone can do it creating both free tier Vercel + Supabase project and DB, respectively.
If you are willing to run it, read the README, specifically about the environment variables.
The root url view tries to connect programmatically via psycopg2 using the DB_PASSWORD variable, and the DATABASE_URL error only occurs if you try to make any request that would use the database, for exampe log in (even with wrong credentials (duh))
The project uses Django (Vercel-hosted) + Postgres (Supabase-hosted).
I don’t usually post in forums, if you have something i could improve in this post feel free to comment.