Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Const

@db

@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.

Since
2.17.0

How it works

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.

Syntax

fieldName ScalarType @db.NativeType(args)

Parameters

NameTypeDescription
typeconnector-specific native typeProvider-specific native database type, optionally accepting arguments such as a length.

Returns

A Prisma schema field annotation that controls the underlying database column type.

Key points

  • Every Prisma scalar has a connector-defined default database type.
  • @db selects the exact native type that Prisma should create.
  • Length-constrained strings can use attributes such as @db.VarChar(200).
  • Migrations honor the native types declared on fields.

Example: Use native database types

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.

When to use it

Control string length

A string column needs a fixed maximum length rather than the connector’s default text mapping.

Select a specialized database type

A field must use a database-specific date, numeric, JSON, or other native representation.

Represent existing column types

A schema must reproduce an existing database’s non-default column types after introspection.

Interview questions

QWhat does the @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.

QWhy would a schema use @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.

QHow is a native type attribute written?

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 types
  • Prisma schema
  • datasource
  • Prisma Migrate
  • Introspection
  • @id
  • @default

Source: Native database types - Prisma ORM. Checked 2026-10-16.