Supporting features without a PSL equivalent

Not all database functions and features have a Prisma Schema Language equivalent. Refer to the database features matrix for a complete list of supported features.

Native database functions

Prisma Schema Language supports several functions that you can use to set the default value of a field. The following example uses the Prisma-level uuid() function to set the value of the id field:

model Post {
id String @id @default(uuid())
}

However, you can also use native database functions to define default values with dbgenerated() . The following example uses the PostgreSQL gen_random_uuid() function to populate the id field:

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

When to use a database-level function

There are two reasons to use a database-level function:

  • There is no equivalent Prisma function (for example, gen_random_bytes in PostgreSQL).

  • You cannot or do not want to rely on functions such uuid() and cuid(), which are only implemented at Prisma level and do not manifest in the database.

    Consider the following example, which sets the id field to a randomly generated UUID:

    model Post {
    id String @id @default(uuid())
    }

    The UUID is only generated if you use Prisma Client to create the Post. If you create posts in any other way, such as a bulk import script written in plain SQL, you must generate the UUID yourself.

Enable extensions for native database functions

Some native database functions are part an extension. For example, gen_random_uuid() is part of the pgcrypto module. You must install the extension in order to use the function:

CREATE EXTENSION IF NOT EXISTS pgcrypto;

If your project uses Prisma Migrate, you must install the extension as part of a migration .

Unsupported field types

Some database types, such as polygon or geometry, do not have a Prisma Schema Language equivalent. Use the Unsupported field type to represent the field in your Prisma schema:

model Star {
id Int @id @default(autoincrement())
position Unsupported("circle")? @default(dbgenerated("'<(10,4),11>'::circle"))
}

The prisma migrate dev and prisma db push command will both create a position field of type circle in the database. However, the field will not be available in the generated Prisma Client.

Unsupported database features

Some features, like SQL views or partial indexes, cannot be represented in the Prisma schema. If your project uses Prisma Migrate, you must include unsupported features as part of a migration .

Edit this page on GitHub