Prisma schema field types
Every field in a Prisma model has a type: a built-in scalar, an enum, another model (a relation), or a composite type. Each scalar maps to a default database column that you can override with a @db native-type modifier. This searchable reference lists the scalar types, relation forms and native modifiers with their default PostgreSQL mapping so you can model schemas precisely.
Scalar types and their default PostgreSQL columns
| Prisma scalar | Default PostgreSQL type | Notes |
|---|---|---|
String | text | Use @db.VarChar(n) to cap length; email columns often use @db.VarChar(320) |
Int | integer | 32-bit signed; for auto-increment PKs pair with @id @default(autoincrement()) |
BigInt | bigint | 64-bit signed; for IDs expected to exceed ~2 billion |
Float | double precision | IEEE 754 floating point; subject to rounding — never use for money |
Decimal | decimal(65,30) | Exact fixed-precision; the right choice for monetary amounts |
Boolean | boolean | Standard true/false |
DateTime | timestamp(3) | Millisecond precision; use @db.Timestamptz(3) to preserve timezone |
Json | jsonb | Stores arbitrary JSON; cannot be deeply queried in a cross-database portable way |
Bytes | bytea | Binary data; useful for file content, hashes, or binary blobs |
How it works
A field is name Type modifiers attributes. Optionality and lists are encoded with ? and [], and native database types are set with @db:
model User {
id Int @id @default(autoincrement())
email String @unique @db.VarChar(320)
balance Decimal @db.Decimal(12, 2)
createdAt DateTime @default(now()) @db.Timestamptz(3)
metadata Json?
posts Post[]
}
The Prisma scalar (String, Decimal, DateTime) chooses the default column, and the @db attribute pins the exact native type. Relations link models by referencing the related model type plus a @relation mapping.
Common mistakes to avoid
Using Float for money. Floating-point arithmetic cannot represent most decimal fractions exactly, so Float values accumulate rounding error across operations. Use Decimal for any monetary amount. For storage, @db.Decimal(12, 2) gives twelve total digits with two decimal places — enough for most currencies up to billions.
Forgetting @db.Timestamptz. Prisma’s default DateTime maps to timestamp(3) in PostgreSQL, which stores a point in time without any timezone information. If your application needs to preserve the timezone offset of an event (for example, a scheduled appointment in a user’s local zone), use @db.Timestamptz(3) so the database stores the timezone-aware value.
Making all string fields String without a length. The default text type has no practical length limit in PostgreSQL, which is fine for long fields. But for fields with a known maximum — email addresses, URLs, slugs — using @db.VarChar(n) communicates the constraint in the schema and the database enforces it as a safety check.
Tips and notes
- Use
Decimal(neverFloat) for money to avoid floating-point rounding. DateTimedefaults totimestamp(3); use@db.Timestamptzto store the zone.Jsonis great for flexible blobs but cannot be deeply queried portably across databases.- Append
?for nullable and[]for list;BigIntmaps to 64-bit integers.