Install Prisma Client
Install and generate Prisma Client
To get started with Prisma Client, you need to install the @prisma/client
package:
npm install @prisma/client
The install command invokes prisma generate
for you which reads your Prisma schema and generates a version of Prisma Client that is tailored to your models.
Whenever you update your prisma schema , you will have to update your database schema using either commands
npx prisma db push
and npx prisma migrate dev
serve different purposes in managing your database schema with Prisma. Here’s a breakdown of when and why to use each:
npx prisma migrate dev
- Purpose: This command generates and applies a new migration based on your Prisma schema changes. It creates migration files that keep a history of changes.
- Use Case: Use this when you want to maintain a record of database changes, which is essential for production environments or when working in teams. It allows for version control of your database schema.
- Benefits: This command also includes checks for applying migrations in a controlled manner, ensuring data integrity.
npx prisma db push
- Purpose: This command is used to push your current Prisma schema to the database directly. It applies any changes you've made to your schema without creating migration files.
- Use Case: It’s particularly useful during the development phase when you want to quickly sync your database schema with your Prisma schema without worrying about migration history.
- Caution: It can overwrite data if your schema changes affect existing tables or columns, so it’s best for early-stage development or prototyping.