I have a prisma db and I am trying to run the deploy command for production.
When running yarn rw prisma migrate deploy , I get an error saying:
1 migration found in prisma/migrations
Error: P3005
The database schema is not empty. Read more about how to baseline an existing production database: https://pris.ly/d/migrate-baseline
What am I doing wrong and how can I fix it?
If you setted up Prisma on an existing database you must skip initial migration as such:
yarn prisma migrate resolve --applied <migration_name>
Its called baselining.
If it doesnt work due to some existing data, you can either rollback changes or fix the data problem and apply a fix with yarn prisma migrate diff
Details are here.
I ran the diff
and applied the resulting file as such:
yarn prisma migrate diff --from-url <DATABASE_URL_PROD> --to-schema-datamodel <path to schema.prisma> --script > forward.sql
yarn prisma db execute --url <DATABASE_URL_PROD> --file forward.sql