Control string length
A string column needs a fixed maximum length rather than the connector’s default text mapping.
Prisma · Const
@db is Prisma’s native database type attribute. It refines a Prisma scalar by selecting the exact provider-specific database type used for the column.
The @db attribute refines a Prisma scalar field with the exact native type used by the configured database provider. Write the provider-specific type after the field declaration; Prisma Migrate then uses that choice when generating the database schema, and introspection adds the attribute when the database type differs from the provider’s default mapping.
fieldName ScalarType @db.NativeType(args)| Name | Type | Description |
|---|---|---|
type | connector-specific native type | Provider-specific native database type, optionally accepting arguments such as a length. |
A Prisma schema field annotation that controls the underlying database column type.
@db selects the exact native type that Prisma should create.@db.VarChar(200).datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @db.VarChar(255)
createdAt DateTime @db.Date
}This schema keeps Prisma scalar types while selecting PostgreSQL-specific column types for the email and createdAt fields.
A string column needs a fixed maximum length rather than the connector’s default text mapping.
A field must use a database-specific date, numeric, JSON, or other native representation.
A schema must reproduce an existing database’s non-default column types after introspection.
@db attribute do?@db is a native database type attribute. It preserves the Prisma scalar type while selecting a provider-specific database type, such as @db.VarChar(200) for a String field.
Follow-up: What determines whether the attribute is valid? The datasource provider determines the available native types and their mapping.
@db.VarChar(200) instead of plain String?Prisma scalar types have default mappings in each connector. An explicit @db attribute overrides that choice, and Prisma Migrate uses the specified type when creating a migration.
Follow-up: What happens during introspection? Prisma represents the column with its Prisma scalar type and adds a native attribute when the native type is not the default.
The attribute is written in PascalCase and is prefixed by @db, where db matches the datasource block name. Examples include @db.VarChar(200) and @db.Date.
Follow-up: Can the same spelling always be reused across databases? No; native types and mappings are connector-specific.
Prisma scalar typesPrisma schemadatasourcePrisma MigrateIntrospection@id@default