How to Reset and Seed a Prisma Project
So, you're messing around with your schema and running a migration using Prisma and realized you need to nuke it and start again?
No worries, I've got you covered.
Here's how to reverse your last migration in a development environment.
Remember, this is for development only, so let's dive in.
Prisma Migrate Reset
If you're okay with starting from scratch, prisma migrate reset
will clean your database and reapply all your migrations from the top.
This command is pretty much the "turn it off and on again" approach, wiping all data in your dev database.
Make sure you don't need the data, and then run:
npx prisma migrate reset
If you have a seed file, that will auto-magically run! 🪄
There doesn't seem to be a straightforward way to undo your last migration without applying more migrations, so I usually use this method.
This is always less painful if you can easily populate the data of the database.
To do this, you can create a seed file.
I've created an article here to show you how.
I hope this helps! 🦾