12

I'm starting a project where I have to learn a new technology and I chose to build a full-stack app with Prisma and Next.js. I'm using both for the first time. I've built front-end apps w/ React.js and feel confident about using Next. However, I'm having a hard time getting started with Prisma. I'm following Prisma's 'Start from Scratch' instructions and I'm stuck on the step "To map your data model to the database schema, you need to use the prisma migrate CLI commands: " and I run the command: npx prisma migrate dev --name init --preview-feature I get the error:


P3014
Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases.  More info: https://pris.ly/d/migrate-shadow. Original error: 
Database error: Error querying the database: db error: ERROR: permission denied to create database

My database is postgresQL and it's hosted on heroku. My DATABASE_URL is copied/pasted from the configs on heroku.

Here are my .json dependencies:

  "name": "photo_album",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "prisma": "prisma",
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "@prisma/client": "^2.13.1",
    "next": "10.0.3",
    "react": "17.0.1",
    "react-dom": "17.0.1"
  },
  "devDependencies": {
    "@prisma/cli": "^2.13.1"
  }
}

I tried Introspect. But, my DB currently has no tables and that threw an error. I tried npx prisma migrate save -experimental b/c of a build I saw on youtube. I tried npm install @prisma/cli --save-dev b/c that worked for the same problem posted here on stackoverflow. Another solution said to use Docker. I haven't tried that yet.

3 Answers3

24

According to nikolasburk you can also run prisma db push instead of the prisma migrate dev command, just run:

npx prisma db push --preview-feature
Ruben Santana
  • 411
  • 5
  • 10
  • 1
    Although it solves the problem temporarily but doesn't solve the permission issue. So as you try to add records through `prisma studio` it won't allow you due to access issues – imran haider Dec 20 '21 at 11:38
15

I could fix this issue by creating another DB in Heroku as my shadow DB. Then in the schema.prisma add the code bellow:

datasource db {
  provider          = "postgresql"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
Ayin
  • 159
  • 1
  • 2
6

Yes this is currently due to the fact that Prisma requires permissions to create a temporary database that applies migrations and the Heroku managed database doesn't provide that. One thing you could do is install Postgres locally and use that for development and the other option would be to follow this workaround from the thread which has the same issue that you're facing.

Ryan
  • 5,229
  • 1
  • 20
  • 31
  • 1
    Thank you for posting this answer! I'm pretty sure it worked. I say pretty sure because I don't see the tables/models on my heroku DB. But, I do see the migration on there! That's a step in the right direction – Benjamin Higginbotham Dec 21 '20 at 15:09
  • 1
    Apparently this is still an issue in 2023. Not using Heroku, but cockroachlabs db. – Fer Toasted Feb 10 '23 at 00:15