drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.64k stars 650 forks source link

[BUG]: Either connection "url" or "host", "database" are required for PostgreSQL database connection #2761

Open caiohportella opened 3 months ago

caiohportella commented 3 months ago

What version of drizzle-orm are you using?

0.32.2

What version of drizzle-kit are you using?

0.23.2

Describe the Bug

My config file is below, following the documentation on configuration:

import { defineConfig } from "drizzle-kit";

export default defineConfig({
  schema: "./lib/db/schema.ts",
  out: "./drizzle",
  dialect: "postgresql",
  dbCredentials: {
    url: process.env.DB_URL!,
  },
  verbose: true,
  strict: true,
});

When running pnpm drizzle-kit push, I get thrown the error at the terminal: Either connection "url" or "host", "database" are required for PostgreSQL database connection.

I wonder why, since the url is my correct URI String connection in my .env.

Expected behavior

No response

Environment & setup

No response

LeulAria commented 3 months ago

try console.log your env process.env.DB_URL if undefined configure you'r env

pippinmole commented 1 month ago

Hi, for some reason drizzle doesnt pick up env files named .env.local, for example. Make sure your env file is named .env.

dani-z commented 1 week ago

If you still want to use .env.local make sure you configure dotenv to use that. My config file looks like

"use server";
import type { Config } from "drizzle-kit";
import { config } from "dotenv";

config({ path: ".env.local" });

export default {
  dialect: "postgresql",
  schema: "./src/lib/db/schema.ts",
  out: "./migrations",
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
  verbose: true,
  strict: true,
} satisfies Config;