Skip to main content
⚑ OpenDevDocs
Prisma
databasesprismaReferenceBeginner

Prisma Models & Field Types

Defining data models, scalar types (String, Int, Boolean, DateTime, Json), field attributes (@id, @default, @unique), and table mapping.

Verified: 2026-10-01
Tested on:prisma 6.x
Platforms:
node
#prisma#models#data-types#attributes#schema

Prisma Models & Field Types

Models in Prisma represent tables (in SQL relational databases) or collections (in MongoDB).


1. Scalar Types

Prisma TypeTypeScript TypePostgreSQL Type Equivalent
Stringstringtext / varchar(n)
Booleanbooleanboolean
Intnumberinteger (4 bytes)
BigIntbigintbigint (8 bytes)
Floatnumberdouble precision
DecimalDecimal (decimal.js)numeric / decimal (Exact precision)
DateTimeDatetimestamp(3)
JsonJsonValuejsonb
BytesBufferbytea

2. Field Modifiers

  • Required Field: title String (Value cannot be null)
  • Optional Field (?): bio String? (Value can be null or undefined)
  • List / Array Field ([]): tags String[] (Supported natively in PostgreSQL)

3. Essential Field Attributes

AttributeDescriptionExample
@idDeclares the primary keyid Int @id @default(autoincrement())
@default(...)Sets a default column valuecreatedAt DateTime @default(now())
@uniqueEnforces unique constraintemail String @unique
@updatedAtAutomatically updates timestamp on editupdatedAt DateTime @updatedAt
@map("col_name")Maps field to a specific SQL columncreatedAt DateTime @map("created_at")

4. Model-Level Attributes

AttributeDescriptionExample
@@map("table_name")Maps model to SQL table name@@map("auth_users")
@@unique([...])Compound unique constraint@@unique([tenantId, slug])
@@index([...])Creates an index on columns@@index([authorId, status])
@@id([...])Composite primary key@@id([userId, organizationId])

5. Comprehensive Example

model OrganizationMember {
  organizationId String   @map("org_id")
  userId         String   @map("user_id")
  role           String   @default("member")
  joinedAt       DateTime @default(now()) @map("joined_at")

  organization   Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
  user           User         @relation(fields: [userId], references: [id], onDelete: Cascade)

  // Composite primary key (Many-to-many join table)
  @@id([organizationId, userId])
  @@index([userId])
  @@map("organization_members")
}

On this page