How to init migration with existing database
I already have a database and there is data in it. Now I want to use Prisma to connect with it .So I do following:
1. Create a schema.prisma file, config datasource and generator
2. Run
prisma db pull
to get latest schema
3. Run prisma migrate dev
to init migration
But step 3 got error, Prisma tells me that my schema is not sync and prompts me to reset database. It will cause data lost so I can't do that.
But if I want to sync a new model (create a new table) added in schema.prisma file, I need to do a migration
How can I solve this problem without data lost?3 Replies
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into
#ask-ai
if you get antsy for a second opinion!You are looking for baselining:
https://www.prisma.io/docs/orm/prisma-migrate/workflows/baselining
Baselining a database | Prisma Documentation
How to initialize a migration history for an existing database that contains important data.
I followed this guide but when I run
prisma migrate resolve --applied 0_init
, error shows The migration 0_init could not be found. This may because the command couldn't recognize dir prisma/migrations
, when I rename to migrations
, this command works, however, then prisma migrate dev
failed when I try to add a model and migtare a new version, error shows Could not find the file at migration.sql
My client version is 6.13