Enable extensions for native database functions
Some native database functions are part of optional extensions. You cannot use the function if the extension is not installed. If your project uses Prisma Migrate, you must install the extension as part of a migration.
This guide does not apply for MongoDB.
MongoDB does not support optional extensions as those do not exist for MongoDB.
Do not manually install extensions - the shadow database requires the same extensions, and since this database is created and deleted automatically, the only way to install extensions is to use migrations.
Installing an extension as part of a migration
The following example demonstrates how to install the pgcrypto
extension as part of a migration:
Add the field with the native database function to your schema:
model User {id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid}If you include a cast operator (such as
::TEXT
), you must surround the entire function with parentheses:@default(dbgenerated("(gen_random_uuid()::TEXT)")Use the
--create-only
flag to generate a new migration without applying it:$npx prisma migrate dev --create-onlyOpen the generated
migration.sql
file and enable thepgcrypto
module:CREATE EXTENSION IF NOT EXISTS pgcrypto;ADD COLUMN "id" UUID NOT NULL DEFAULT gen_random_uuid(),ADD PRIMARY KEY ("id");Apply the migration:
$npx prisma migrate dev
Each time you reset the database or add a new member to your team, all required functions are part of the migration history.