Skip to content

Instantly share code, notes, and snippets.

@alfasin
Last active February 16, 2025 21:22
Show Gist options
  • Save alfasin/d6ed2386c101b2af681b135752488cce to your computer and use it in GitHub Desktop.
Save alfasin/d6ed2386c101b2af681b135752488cce to your computer and use it in GitHub Desktop.
Reset Prisma instead of resetting your DB
# before you start: go to prisma.schema and copy aside the sections: "generator client {...}" and "datasource db {...}"
# the may contain previewFeatures and extensions that won't be recovered automatically and you'll have to add them manually in a few steps!
# Go to your DB and drop the migrations table: `DROP TABLE _prisma_migrations`
# From the root of the project:
rm -rf prisma
npx prisma init
npx prisma db pull # This should recreate prisma.schema file from the DB
# copy the sections that you saved in the beginning ("generator client" and "datasource db") into the beginning of the generated prisma.schema file (instead of the related generated code).
# the following is taken from: https://www.prisma.io/docs/orm/prisma-migrate/getting-started#create-a-baseline-migration
mkdir -p prisma/migrations/0_init
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql
npx prisma migrate resolve --applied 0_init
npx prisma generate
# and that's it - now you should be able to run `npm run migrate` smoothly!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment