Warm tip: This article is reproduced from serverfault.com, please click

Error when migrating models to database Prisma

发布于 2020-12-20 21:10:30

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.

Questioner
Benjamin Higginbotham
Viewed
0
Ryan 2020-12-21 14:45:15

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.