Overview
Models represent tables in your database and define the structure of your data. Each model maps to a database table and contains fields that define columns.Basic Syntax
Model Structure
Naming Conventions
Model names:- Use PascalCase (e.g.,
User,Post,BlogPost) - Should be singular (Prisma pluralizes table names by default)
- Must start with a letter
- Can contain letters, numbers, and underscores
Simple Model Example
Model Features
Required vs Optional Fields
Fields are required by default. Add? for optional fields:
Database Table Mapping
By default, model names map to table names. Use@@map to customize:
Model Comments
Add documentation to your models:Complete Model Examples
User Management
Blog Post
E-commerce Product
User Profile
Authentication Tokens
Course Enrollment (Many-to-Many)
Model Organization
Grouping Related Models
Organize related models together:Model Ignoring
Exclude models from Prisma Client generation:- Legacy tables you don’t need in your application
- Temporary migration tables
- Database-specific system tables
Best Practices
- Use singular, PascalCase names for models
- Add comments for complex models or business logic
- Group related models together in your schema
- Use meaningful field names that reflect your domain
- Consider using
@@mapfor existing databases with different naming conventions - Always include timestamp fields (
createdAt,updatedAt) for auditing - Use appropriate field types for your data (covered in Field Types documentation)