prisma: `npx prisma migrate dev` hangs up

Bug description

When running the command npx prisma migrate dev, it hands up after returning the following message:

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:54322"

It stays like that potentially forever, I’ve let it run for more than one hour at the time.

The project I’m having issues with is a createt3-app, and the database is hosted on supabase.

How to reproduce

  1. Followed all the steps in this tutorial.

Relevant parts of the video are 2:50 - 8:20 for the project set up, and 16:10 forward for the migration.

Expected behavior

I expected the npx prisma migrate dev command to work.

Prisma information

// Add your schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
    provider = "prisma-client-js"
}

datasource db {
    provider = "postgresql"
    // NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
    // Further reading:
    // https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
    // https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
    url      = env("DATABASE_URL")
}

model Example {
    id        String   @id @default(cuid())
    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

// Necessary for Next auth
model Account {
    id                String  @id @default(cuid())
    userId            String
    type              String
    provider          String
    providerAccountId String
    refresh_token     String? 
    access_token      String? 
    expires_at        Int?
    token_type        String?
    scope             String?
    id_token          String? 
    session_state     String?
    user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

    @@unique([provider, providerAccountId])
}

model Session {
    id           String   @id @default(cuid())
    sessionToken String   @unique
    userId       String
    expires      DateTime
    user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
    id            String    @id @default(cuid())
    name          String?
    email         String?   @unique
    emailVerified DateTime?
    image         String?
    accounts      Account[]
    sessions      Session[]
}

model VerificationToken {
    identifier String
    token      String   @unique
    expires    DateTime

    @@unique([identifier, token])
}

// Add your code using Prisma Client
/* eslint-disable no-var */
import { PrismaClient } from "@prisma/client";
import type { SupabaseClient } from "@supabase/supabase-js";
import { createClient } from "@supabase/supabase-js";

import { env } from "../env/server.mjs";

declare global {
  var prisma: PrismaClient | undefined;
  var supabase: SupabaseClient | undefined;
}

export const prisma =
  global.prisma ||
  new PrismaClient({
    log:
      env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
  });

if (env.NODE_ENV !== "production") {
  global.prisma = prisma;
}

Environment & setup

  • OS: macOS Monterey 12.5, MacBook Air M1 2020
  • Database: PostgreSQL on Supabase
  • Node.js version: v16.18.0

Prisma Version

npx prisma -v
Environment variables loaded from .env
prisma                  : 4.8.1
@prisma/client          : 4.8.1
Current platform        : darwin-arm64

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 19 (3 by maintainers)

Most upvoted comments

SOLUTION:

Supabase also needs DIRECT_URL apart from DATABASE_URL

Here were the changes in my project:

Before(HANGS):

datasource db {
  provider     = "mysql"
  relationMode = "prisma"
  url          = env("DATABASE_URL")
}

image

AFTER(MIGRATES SUCCESSFULLY)

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}

image

By default, the port in the . env database URL is 6543, passing it to 5432 solved my problem.

This page from Supabase describes pretty well how you need to set up your project for it to work with Prisma: https://supabase.com/partners/integrations/prisma

SOLUTION:

Supabase also needs DIRECT_URL apart from DATABASE_URL

Here were the changes in my project:

Before(HANGS):

datasource db {
  provider     = "mysql"
  relationMode = "prisma"
  url          = env("DATABASE_URL")
}

image

AFTER(MIGRATES SUCCESSFULLY)

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_URL")
}

image

thanks so much, its works

I have also facing same issue, its not creating model or table inside database

Read the message I posted before. It includes a workaround in the linked issue.