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.

db push --force-reset is not creating database if it doesn't exist

See original GitHub issue

Bug description

running npx prisma db push --force-reset for a database that does not exist gives me an error instead of creating the database.

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "mydb-test", schema "public" at "localhost:5432"

Response: Database `mydb-test.public` does not exist on the database server at `localhost:5432`.
Error: UserFacingError

If I manually create the database using the same user then running npx prisma db push --force-reset my schema is correctly setup.

With debug output

DEBUG="*" npx prisma db push --force-reset                                                                                                         ─╯
  prisma:loadEnv project root found at {MY_PATH}/backend/package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from {MY_PATH}/backend/.env +0ms
Environment variables loaded from .env
  prisma:engines using NAPI: false +0ms
  prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +1ms
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig Using Query Engine Binary at: {MY_PATH}/backend/node_modules/@prisma/engines/query-engine-darwin +0ms
Datasource "db": PostgreSQL database "mydb-test", schema "public" at "localhost:5432"
  prisma:getConfig Using Query Engine Binary at: {MY_PATH}/backend/node_modules/@prisma/engines/query-engine-darwin +51ms

  prisma:migrateEngine:rpc starting migration engine with binary: {MY_PATH}/backend/node_modules/@prisma/engines/migration-engine-darwin +0ms
  prisma:migrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"reset","params":{}} +18ms
  prisma:migrateEngine:stderr Jun 03 15:42:09.053  INFO migration_engine: Starting migration engine RPC server git_hash="f3e341280d96d0abc068f97e959ddf01f321a858" +0ms
Error: Error: UserFacingError
    at ChildProcess.<anonymous> ({MY_PATH}/backend/node_modules/prisma/build/index.js:57396:28)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)

This was working fine until I tried to run my integration tests today.

I was on 2.23.0 when I first saw the error and then tried on 2.24.0 and saw the same issue.

How to reproduce

run npx prisma db push --force-reset

Expected behavior

A database is created if it does not already exist

Prisma information

now it's closed I've removed the schema that was pasted here

Environment & setup

  • OS: MacOS BigSur 11.4
  • Database: PostgreSQL 13.2 (Debian 13.2-1.pgdg100+1)
  • Node.js version: 14.16.1

PostgreSQL is running in a docker container with an exposed port of 5432 prisma is running on host os

Prisma Version

prisma               : 2.24.0
@prisma/client       : 2.24.0
Current platform     : darwin
Query Engine         : query-engine f3e341280d96d0abc068f97e959ddf01f321a858 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli f3e341280d96d0abc068f97e959ddf01f321a858 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core f3e341280d96d0abc068f97e959ddf01f321a858 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt f3e341280d96d0abc068f97e959ddf01f321a858 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : f3e341280d96d0abc068f97e959ddf01f321a858
Studio               : 0.397.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomhoulecommented, Jul 3, 2021

Starting migration engine RPC server

This should not be showing up in the error, we need to look into that as well. It’s probably a problem with the new error handling code in the CLI.

1reaction
pantharshit00commented, Jun 15, 2021

I can reproduce this with 2.25. Looks like only happening with --force-reset

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create database if db does not exist - Stack Overflow
Could you check the following script : IF NOT EXISTS(SELECT * FROM sys.databases WHERE name = 'DataBase') BEGIN CREATE DATABASE [DataBase] ...
Read more >
Prototype your schema - Prisma
The Prisma CLI has a dedicated command for prototyping schemas: db push. db push uses the same engine as Prisma Migrate to synchronize...
Read more >
Back up and restore GitLab
An application data backup creates an archive file that contains the database, all repositories and all attachments. You can only restore a backup...
Read more >
Database Engine events and errors - SQL Server
ls' already exists, or you do not have permission to create it. ... Cleanup will be attempted again on database restart.
Read more >
Command Line Interface | RedwoodJS Docs
Example The following command will build, apply Prisma DB migrations, and skip data migrations. yarn redwood deploy netlify --no-data-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