question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Migrate dev fails

See original GitHub issue

Bug description

Hello I am following this NestJS + Prisma / PostgreSQL tutorial until this command fails :

npx prisma migrate dev --name init --preview-feature

ā€¦ using this env variable :

DATABASE_URL="postgresql://postgres:postgres@localhost:5432/testdb?schema=public"

results in :

Environment variables loaded from .env Prisma schema loaded from prisma\schema.prisma Datasource ā€œdbā€: PostgreSQL database ā€œtestdbā€, schema ā€œpublicā€ at ā€œlocalhost:5432ā€ Error: P1001: Canā€™t reach database server at localhost:5432 Please make sure your database server is running at localhost:5432. ā€¦

I tried with other ORMs, pg and vanilla psql createdb without issue, using same connection string.

i also tried modifying pg_hba.conf to allow local and host for all with trust method, without success ā€¦

Expected behavior

I expect Prisma to connect properly, like with Sequelize/Typeorm/pg/psql ā€¦ and create the database testdb.

Environment & setup

  • OS: Windows 10.0.19042
  • Database: PostgreSQL 13.1 (freshly installed from scratch)
  • Node.js version: 15.5.0
  • Prisma version: using npx prisma so latest 2.13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jthncommented, Jan 11, 2021

I am following this NestJS + Prisma / PostgreSQL tutorial until this command fails :

@Sharlaan, I could be mistaken about this (and would love clarification if I am wrong), but I donā€™t believe that the migrate command creates the initial database.

Also, the tutorial you linked is using SQLite, which doesnā€™t require anything except a file (donā€™t quote me on that, but it is much simpler). You might note in the expanded section on MySQL/Postgres, they reference the process for creating a database.

When I have set this up on my end, I had to create the database myself. To be honest, Iā€™d love it if the tool would take care of creation for me (one less thing to document), but I donā€™t think it does.

1reaction
sylquecommented, Sep 29, 2022

I had the same issue and solved it by manually creating the database, as the migrate command doesnā€™t do it. Thanks for the tip @jthn.

I think this issue should be reoppened, as the prisma error message is wrong and misleading: ā€œError: P1001: Canā€™t reach database server at localhost:5432ā€ should rather be ā€œError: non-existent database ā€˜mydbā€™ā€.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migration troubleshooting in development - Prisma
The easiest way to handle a failed migration in a developer environment is to address the root cause and reset the database. For...
Read more >
Migration dev error Ā· Issue #11668 Ā· prisma/prisma - GitHub
Bug description Hi, When doing a migrate dev after a successful migration I've got this error Database error code: 1146 Database error:Ā ...
Read more >
Prisma: 'npx prisma migrate dev' fails to connect with Supabase
Prisma: 'npx prisma migrate dev' fails to connect with Supabase Ā· Changed the password of the supabase db to ensure that I am...
Read more >
Troubleshooting migration tasks in AWS Database Migration ...
Primary key violation errors occur when you restart a task. This error can occur when data remains in the target database from a...
Read more >
Prisma on Twitter: " You can use migrate diff to go forward or ...
āœ“ Here's an example of the flow to determine what additional steps are needed to resolve a failed schema migration, using the `migrate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found