P
Prisma3w ago
Babu

Database url is mission

hi i am facing same issue just like this and the instruction is give by bot it's already done expect npm install dotenv and after doing last step still i am facing some issue https://discord.com/channels/937751382725886062/1431070857253490688 and i am facing this issue when i run this comman
npx prisma migrate dev --name init
npx prisma migrate dev --name init
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
engine: "classic",
datasource: {
url: env("DATABASE_URL"),
},
});
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
engine: "classic",
datasource: {
url: env("DATABASE_URL"),
},
});
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

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

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


model Product {
id String @id @default(cuid())
userId String
name String
sku String? @unique
price Decimal @db.Decimal(12,2)
quantity Int @default(0)
lowStockAt Int?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([userId, name])
@@index([createdAt])
}
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

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

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


model Product {
id String @id @default(cuid())
userId String
name String
sku String? @unique
price Decimal @db.Decimal(12,2)
quantity Int @default(0)
lowStockAt Int?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@index([userId, name])
@@index([createdAt])
}
3 Replies
Prisma AI Help
You chose to compile with the bot. One moment while I piece together your answer… It looks like you are using a prisma.config.ts file with the new Prisma config format. When using this approach, Prisma does not automatically load environment variables from your .env file. You must explicitly load them using the dotenv package. Steps to fix: 1. Install dotenv if you haven't:
npm install dotenv

npm install dotenv

2. Import dotenv/config at the top of your prisma.config.ts:
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
engine: "classic",
datasource: {
url: env("DATABASE_URL"),
},
});

import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
engine: "classic",
datasource: {
url: env("DATABASE_URL"),
},
});

This ensures that process.env.DATABASE_URL is available when Prisma runs. 3. Make sure your .env file is in your project root (or wherever your config expects), and that it contains:
DATABASE_URL="postgresql://user:password@localhost:5432/dbname?schema=public"

DATABASE_URL="postgresql://user:password@localhost:5432/dbname?schema=public"

Why this is needed:
With the new Prisma config, environment variables from .env files are not loaded automatically. You must use dotenv to load them yourself. This is documented behavior and a common stumbling block when migrating to the new config system see here and here. Summary:
- Add import "dotenv/config"; to your prisma.config.ts. - Ensure your .env file is correct and in the right place. - Then run your Prisma CLI commands again. If you still see the error, double-check the spelling and path of your .env file, and make sure DATABASE_URL is set correctly (no extra spaces, colons, or typos) see example. Let me know if you need more help!
Aman
Aman3w ago
Add import "dotenv/config" on top of prisma.config.td
Babu
BabuOP3w ago
thanks it work

Did you find this page helpful?