prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.94k stars 1.56k forks source link

I get the following Error when runing prisma migrate #22566

Closed amine-tayani closed 11 months ago

amine-tayani commented 11 months ago

Bug description

Datasource "db": PostgreSQL database

Error: Prisma schema validation - (get-config wasm) 
Error code: P1012
error: Environment variable not found: DATABASE_URL.
  -->  schema.prisma:6
   | 
 5 |   provider = "postgresql"
 6 |   url      = env("DATABASE_URL")
   | 

Validation Error Count: 1
[Context: getConfig]

How to reproduce

  1. Run pnpm dlx prisma migrate dev or pnpm dlx prisma db push
  2. terminal shows the error above.

Expected behavior

should run the migrations and supabase should show the tables

Prisma information

Schema.prisma file

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

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

enum ApplicationStatus {
  APPLIED
  INTERVIEW
  REJECTED
  OFFER
  CLOSED
}

model Account {
  id                 String    @id @default(cuid())
  userId             String
  providerType       String
  providerId         String
  providerAccountId  String
  refreshToken       String?
  accessToken        String?
  accessTokenExpires DateTime?
  createdAt          DateTime  @default(now())
  updatedAt          DateTime  @updatedAt
  user               User      @relation(fields: [userId], references: [id])

  @@unique([providerId, providerAccountId])
}

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

model UserLink {
  id        String   @id @default(uuid())
  user      User[]
  url       String   @db.VarChar(256)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model ImageUpload {
  id        String   @id @default(uuid())
  userId    String
  user      User     @relation(fields: [userId], references: [id])
  url       String   @db.VarChar(256)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@index([userId])
}

model User {
  id             String        @id @default(cuid())
  hashedPassword String?
  email          String?       @unique
  emailVerified  DateTime?
  name           String?
  bio            String?       @default("") @db.VarChar(1000)
  image          String?
  location       String?
  experience     Int?
  skills         String[]
  createdAt      DateTime      @default(now())
  updatedAt      DateTime      @updatedAt
  accounts       Account[]
  sessions       Session[]
  socialLinks    UserLink[]
  imageUpload    ImageUpload[]
}

model Application {
  id           Int               @id @default(autoincrement())
  company      String
  title        String
  description  String            @db.Text
  location     String
  Url          String?
  datePosted   DateTime
  deadlineDate DateTime?
  status       ApplicationStatus @default(APPLIED)
}

model VerificationRequest {
  id         String   @id @default(cuid())
  identifier String
  token      String   @unique
  expires    DateTime
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  @@unique([identifier, token])
}

Environment & setup

Prisma Version

prisma@5.7.1 @prisma/client@5.7.1

millsp commented 11 months ago

Hey @amine-tayani, did you place your environment variable in a .env file or exported it in your shell first?

amine-tayani commented 11 months ago

hey @millsp i have already setup the .env.local file with DATABASE_URL variable

amine-tayani commented 11 months ago

i set it up like this : DATABASE_URL=postgresql://postgres................... without any double quotes or anything

millsp commented 11 months ago

Prisma will only load .env files so .env.local is not loaded. You can either rename your .env.local to .env, or create a .env. Alternatively, you can use the dotenv cli instead, for example:

dotenv -e .env.local -- npx prisma generate
amine-tayani commented 11 months ago

Seems to have worked. Thanks @millsp