Overview
Fields define the structure of your models and map to columns in your database. Each field has a type and optional attributes that control its behavior.Scalar Types
String
Text data of any length:Int
Integer numbers:BigInt
Large integer numbers:Float
Floating-point numbers:Decimal
Precise decimal numbers (for currency, financial data):Boolean
True/false values:DateTime
Date and time values:Json
JSON data structures:Bytes
Binary data:List Types
Arrays of scalar types:Optional Fields
Make fields optional with?:
Native Database Types
Use@db attribute for database-specific types.
PostgreSQL Native Types
MySQL Native Types
SQLite Native Types
SQL Server Native Types
Enum Types
Define custom enumerations:Relation Fields
Relation fields define connections between models:Unsupported Types
For database types not yet supported by Prisma:Field Defaults
Set default values for fields:autoincrement()- Auto-incrementing integernow()- Current timestampuuid()- Generate UUIDcuid()- Generate CUIDdbgenerated("SQL")- Database-generated value
Auto-Update Fields
Automatically update timestamp on record changes:Complete Example
Best Practices
- Use appropriate scalar types for your data
- Leverage native database types for optimization
- Use
Decimalfor financial data, notFloat - Make fields optional with
?only when necessary - Use enums for fields with fixed sets of values
- Add
createdAtandupdatedAttimestamp fields - Use lists sparingly (consider relations instead)
- Choose database-native types for better performance
- Use
@dbattributes for fine-grained control over column types