Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when migrating models to database Prisma

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.

like image 807
Benjamin Higginbotham Avatar asked Nov 30 '22 13:11

Benjamin Higginbotham


2 Answers

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
like image 175
Ruben Santana Avatar answered Jan 28 '23 06:01

Ruben Santana


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")
}
like image 30
Ayin Avatar answered Jan 28 '23 04:01

Ayin