prisma: Migrate dev fails
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 atlocalhost
: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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (8 by maintainers)
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’”.
@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.