Hi, I am trying to start using `prisma migrate` wi...
# orm-help
s
Hi, I am trying to start using
prisma migrate
with an existing DB (without resetting/losing my data), and finding the docs quite confusing -> https://www.prisma.io/docs/guides/application-lifecycle/add-prisma-migrate-to-a-project#baseline-your-production-environment It suggests using
prisma migrate dev
to establish a new migration history, but this tries to run a migration -- and fails, saying it's out of sync. Anyone able to show me the way? 🙏
✔️ 1
r
@Shane 👋 First you would need to create the migration files on your dev environment by following this. After that you can use baselining for your production database.
s
Hey @Ryan thanks for taking the time to help! The second command in that page is to run the
prisma migrate dev
command, and it wants to reset the db 😕
Copy code
› npx prisma migrate dev
Environment variables loaded from ../.env
Prisma schema loaded from schema.prisma
Datasource "db": MySQL database "appdb" at "127.0.0.1:3306"

? Drift detected: Your database schema is not in sync with your migration history.

We need to reset the MySQL database "appdb" at "127.0.0.1:3306".
Do you want to continue? All data will be lost. › (y/N)
r
Yes during an initial transition you have to reset your database so there will be data loss. Which is why this should be run on a dev database where data is not important.
s
Ahhh ok -- so first run on dev (which establishes the migration files) then run it on prod
r
Yeah.
prisma migrate dev
on dev and then Baselining on prod.
s
Ok got it. Thanks for helping me to understand
💯 2
r
Also run
prisma introspect
before dev as per the docs to get the schema in place 🙂
s
Cool 😄