P
Prisma•2mo ago
beanbeanjuice

You don't have any datasource defined in your schema.prisma.

I'm trying to migrate to the new prisma.config.ts as outlined in the latest announcement. I'm running into this error.
╰─ npx prisma generate
Loaded Prisma config from prisma.config.ts.

Prisma config detected, skipping environment variable loading.
Prisma schema loaded from prisma\schema.prisma
Error:
You don't have any datasource defined in your schema.prisma.
You can define a datasource like this:

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

More information in our documentation:
https://pris.ly/d/prisma-schema
╰─ npx prisma generate
Loaded Prisma config from prisma.config.ts.

Prisma config detected, skipping environment variable loading.
Prisma schema loaded from prisma\schema.prisma
Error:
You don't have any datasource defined in your schema.prisma.
You can define a datasource like this:

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

More information in our documentation:
https://pris.ly/d/prisma-schema
This is my prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
import * as path from "node:path";
export default defineConfig({
// The Rust-compiled schema engine
engine: "classic",
schema: path.join("prisma", "schema.prisma"),
migrations: {
path: path.join("prisma", "migrations"),
seed: "ts-node -r tsconfig-paths/register prisma/seed.ts",
},
datasource: {
url: env("DATABASE_URL"),
},
});
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
import * as path from "node:path";
export default defineConfig({
// The Rust-compiled schema engine
engine: "classic",
schema: path.join("prisma", "schema.prisma"),
migrations: {
path: path.join("prisma", "migrations"),
seed: "ts-node -r tsconfig-paths/register prisma/seed.ts",
},
datasource: {
url: env("DATABASE_URL"),
},
});
Is it because I have the "schema" defined? My understanding is that I don't nee dto have it defined in schema.prisma anymore? Am I incorrect (as usual)? 😭
3 Replies
Prisma AI Help
Prisma AI Help•2mo ago
Skipping coffee for instant knowledge! Let's brew that AI answer now. You still need to define a datasource block in your schema.prisma file. The prisma.config.ts file does not replace the need for a datasource in the schema itself. The error message you’re seeing:
You don't have any datasource defined in your schema.prisma.
You can define a datasource like this:

datasource db {
provider = "postgresql"
url = env("DB_URL")
}
You don't have any datasource defined in your schema.prisma.
You can define a datasource like this:

datasource db {
provider = "postgresql"
url = env("DB_URL")
}
means that your schema.prisma is missing the required datasource block. The Prisma CLI and engines still expect the datasource to be defined in the schema.prisma file, even if you are using prisma.config.ts for configuration. The config file can help with things like specifying the schema location, migrations path, and seeding, but it does not inject the datasource into the schema automatically. You must add a datasource block to your schema.prisma, for example:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
The url field can reference an environment variable, and you can load it with dotenv as you are doing in your config, but the block itself must exist in the schema.prisma file. This is confirmed by the documentation and error messages you are seeing Prisma schema reference. So, to resolve the error, add the datasource block to your schema.prisma. The prisma.config.ts does not remove the need for this block in the schema file itself.
beanbeanjuice
beanbeanjuiceOP•2mo ago
Oh.. hmm
Prisma AI Help
Prisma AI Help•2mo ago
✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?