P1001: Can't reach database server
Whenever I run this command:
npx prisma migrate dev --name init
, I end up getting this error:
I'm pretty sure that i've tried everything. I have tried to ping it with my command prompt, using DataGrip, and asked ChatGPT, yet I just can't get it to work.3 Replies
You opted for speed from this bot. Let's conjure up an answer right now!
Based on the information provided in the knowledge sources, it appears that you're experiencing a common issue when trying to connect Prisma to a Supabase database. Here are a few potential solutions and things to check:
1. Connection string: Make sure your DATABASE_URL in the .env file is correctly formatted. For Supabase, it should look like this:
2. Direct URL: Supabase recommends using both a DATABASE_URL and a DIRECT_URL in your .env file. Add a DIRECT_URL like this:
Then update your schema.prisma file to include the directUrl:
3. Port: Some users have reported success by changing the port from 5432 to 6543 in the DATABASE_URL. Try this if the above doesn't work.
4. PgBouncer: If you're using PgBouncer with Supabase, add
?pgbouncer=true
to your connection string:
5. IP Whitelist: Make sure your IP address is whitelisted in your Supabase project settings.
6. Check Supabase status: Ensure that your Supabase project is active and the database is running.
If none of these solutions work, you may want to try connecting to the database using psql
command-line tool to verify if it's a Prisma-specific issue or a general connection problem.
For more detailed information and troubleshooting steps, you can refer to these GitHub issues:
- Unable to reach database server at aws-0-us-east-1.pooler.supabase.com:5432 using Prisma migrate dev
- Can't reach database server at postgres
:5432
If you're still u
nable to connect after trying these solutions, you may need to open a new issue on the Prisma GitHub repository with more details about your specific setup.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.I've also tried using different ports.
This is likely because your network doesn't support IPv6.
Can you try changing your network? The other option would be to use the pooled connection string from Supabase