error: the datasource.url property is required in your prisma config file when using prisma migrate dev.
Fixes Prisma's migrate dev refusing to run because datasource.url is missing. Use when the CLI complains about the url property, when DATABASE_URL is not picked up from the env, or when an agent generated a schema.prisma without a url line. Not for connection failures after the url is set, for migration conflicts, or for shadow-database errors.
TL;DR
prisma migrate dev needs a url on the datasource block, and the common setup reads it from an env var that isnt set in your shell. Add url = env("DATABASE_URL") to the datasource block in schema.prisma and export DATABASE_URL in the same terminal before running migrate dev.
error: the datasource.url property is required in your prisma config file when using prisma migrate dev.Use this when
prisma migrate devexits immediately with the datasource.url error- The schema has a datasource block but no
url =line - An agent scaffolded the Prisma project and skipped the env wiring
Not for this skill when
- The url is set but the DB refuses the connection (thats a connection-string problem)
migrate devfails later on a migration conflict or drift warning- The error appears for
migrate deploy(same fix shape, but deploy reads env differently in CI)
Steps
- Open schema.prisma and confirm the datasource block is missing its url:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}Expected output: if the url line is absent, add it exactly as shown. Do not hardcode a connection string here, use the env lookup.
- Set DATABASE_URL in the terminal where you run Prisma. A
.envfile in the project root works for the CLI:
Add this line to the .env file in your project root:
DATABASE_URL="postgresql://YOUR_USER@YOUR_HOST:5432/YOUR_DB"Then confirm it is there:
cat .envExpected output: the .env file contains the DATABASE_URL line. Use your real user, host, and database name; keep any credential out of the schema file itself.
- Verify the env var is visible to the Prisma CLI, then run migrate dev:
npx prisma validate
npx prisma migrate dev --name initExpected output: validate prints "The schema at prisma/schema.prisma is valid", and migrate dev creates the migration instead of the datasource.url error.
- If the error persists with
.envpresent, the env file isnt being loaded: Prisma CLI loads.envfrom the project root (or the schema dir in older versions). Move the schema reference explicitly:
npx prisma migrate dev --schema=./prisma/schema.prisma --name initExpected output: the migration proceeds. Newer Prisma versions also support dotenv path flags if your env file lives elsewhere.
Variant phrasings
same error when running migrate deploy in CI
migrate deploy doesnt read .env files the same way; export DATABASE_URL in the CI job environment instead of relying on a file.
error after switching providers
Each provider needs its own url format. A postgres URL in a mysql datasource still fails later at connect time, so match the URL scheme to provider.
Why it happens
Prisma separates config (schema.prisma) from secrets (env vars). The datasource block must declare where the URL comes from even when the value is injected at runtime. Agents and templates often generate a schema without the url = env(...) line, or the developer runs the CLI in a shell where DATABASE_URL was never exported, so the CLI reports the property missing rather than the value being wrong.
Edge cases
- Multiple schemas in a monorepo: each schema.prisma needs its own datasource block with url.
prisma db pushneeds the same url; it wont error the same way but will fail to connect.- On Prisma 5+,
datasource.urlcan also come from aprisma.config.ts; mixing both files confuses the resolution, so pick one.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstjEKAXfYUSKV0TQiK3Qbkw
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.