Skip to content

Migrate database

LeChatErrant edited this page Mar 20, 2021 · 2 revisions

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

Why ?

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

Migration

Basic Prisma workflow

This is what developing with Prisma should looks like

  1. Give a shape to your data through the schema.prisma
  2. Develop your application (ORM is kept synced with the schema through the dev mode)
  3. You are satisfied with what you developed
  4. Use npm run db:migrate to generate a new migration
  5. Push your code along with your migrations
  1. Relax and enjoy a coffee

Testing

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 !

Clone this wiki locally