-
Notifications
You must be signed in to change notification settings - Fork 6
Migrate database
⚠️ Reading the Database section first is strongly recommanded
You've written a new model, your application builds, but crashes when you try to access the database because 'the field doesn't exist' ? You are at the right place
Prisma is an ORM
Prisma is not a database. PostgreSQL is your database
It means writing models in your schema.prisma generates code, but doesn't affect your database.
The error everybody made the first time is believing that your database is synced with your code, but it isn't ! That's why you need migrations.
Migrations translates what's in your code into SQL used to format the database

This is what developing with Prisma should looks like
- Give a shape to your data through the schema.prisma
- Develop your application (ORM is kept synced with the schema through the dev mode)
- You are satisfied with what you developed
- Use
npm run db:migrateto generate a new migration - Push your code along with your migrations
- Relax and enjoy a coffee
But how can you test your application in local first ?
npm run db:push will simply push the state of your Prisma schema to the database without using migrations.
It's perfect for prototyping and local development !