Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create an initial prisma migration

I have a PostgreSQL database and prisma schema. My migration history is empty and I don't have migrations table. When I am trying to run prisma migrate dev to create migrations table and add initial migration to this table it wants to delete all my database table's data.
prisma migrate dev --name migration_name --create-only command tries to reset my database too.
How to create initial prisma migration without losing my data?
Is it possible to create prisma migrations table in my PostgreSQL database and add initial migration to this table without losing data? I've tried to follow this article: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/add-prisma-migrate-to-a-project but it wants to reset my database after db pull.

like image 917
Yoo SungHee Avatar asked Sep 02 '26 18:09

Yoo SungHee


1 Answers

You can follow these steps to generate the initial migration without resetting your database.

mkdir -p prisma/migrations/init
npx prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > prisma/migrations/init/migration.sql
npx prisma migrate resolve --applied init
npx prisma migrate dev # it should say everything is in sync
like image 90
Nurul Sundarani Avatar answered Sep 05 '26 06:09

Nurul Sundarani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!