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.

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.

The following example demonstrates how to install the pgcrypto extension as part of a migration:

  1. Add the field with the native database function to your schema:

    model User {
    id String @id @db.Uuid @default(dbgenerated("gen_random_uuid()"))
    }

    If you include a cast operator (such as ::TEXT), you must surround the entire function with parentheses:

    @default(dbgenerated("(gen_random_uuid()::TEXT)")
  1. Use the --create-only flag to generate a new migration without applying it:

    $npx prisma migrate dev --create-only
  2. Open the generated migration.sql file and enable the pgcrypto module:

    CREATE EXTENSION IF NOT EXISTS pgcrypto;
    ADD COLUMN "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    ADD PRIMARY KEY ("id");
  3. 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.

Edit this page on GitHub