Why `prisma generate --sql` needs to have `DATABASE_URL`?
I'm getting this error when executing
prisma generate --sql but not if executing prisma generate:
Why does --sql need to connect to the DB? May I disable it?2 Replies
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
The
prisma generate --sql command requires the DATABASE_URL environment variable because it needs an active database connection to generate the TypedSQL functionality. This is a new feature in Prisma that allows for type-safe raw SQL queries.
According to the TypedSQL documentation:
TypedSQL requires an active database connection to parse the SQL and return type information. This means that you need to have a running database when generating the Prisma Client with TypedSQL enabled.This requirement is causing issues for users who want to run
prisma generate in environments where they don't have a running database, such as in CI/CD pipelines or during the build process.
Unfortunately, there's currently no way to disable this requirement when using the --sql flag. However, there are a few workarounds you can consider:
1. Provide a valid DATABASE_URL during the build process.
2. Generate the Prisma Client without the --sql flag in your CI/CD environment.
3. Generate the Prisma Client with --sql locally and commit the generated files to your repository.
The Prisma team is aware of this limitation and there's an open issue discussing potential solutions: Remove requirement for a running database when using TypedSQL.
For now, if you don't need the TypedSQL functionality in your build environment, you can simply use prisma generate without the --sql flag to avoid this error.Hey @angelcervera 👋
Currently, it is a requirement to have a active database connection for
--sql command to work.
We have a feature request to remove this requirement:
https://github.com/prisma/prisma/issues/25124GitHub
Remove requirement for a running database when using TypedSQL · Iss...
Problem When using the new TypedSQL functionality of Prisma ORM, you need to have a running database. This is because the functionality relies on the database to parse the SQL and return type infor...