Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"prisma migrate dev" on existing database

im trying to setup prisma migrate on a database (mysql) already populated with data on my dev enviroment but so far i can't make it work.

1. I did prisma db pull to create the schema from it (works fine). When running prisma migrate dev --name initial-migration --create-only i get a warning asking to RESET the database... i dont want that. So...

2. Run this command prisma migrate diff --from-empty --to-schema-datamodel prisma/schema.prisma --script > migration.sql and manually move the sql file to a manually created prisma/migrations/init folder

3. Now i try to baseline that migration running prisma migrate resolve --applied "initial"

i get an error saying the migration cant be found.. but it's there and even prisma knows it.,..

console capture of the error

like image 686
Bandinopla Avatar asked Aug 04 '26 06:08

Bandinopla


1 Answers

You could achieve what you want by following these steps

  1. Backup your database first; mysqldump --user=root --password="" database_name > database_name.sql
  2. Setup prisma and do; npx prisma db pull
  3. Perform a prisma migration; npx prisma migrate dev --name your_migration_name
  4. Open the command line which comes with your database and type in; mysql --user=your_username --password=your_password
  5. Then choose your database; mysql[(none)]>>use database_name
  6. You can now run the sql file containing your backup file in your database as such; mysql[database_name]>> source C:\path\to\your\database_backupfile\database_name.sql You should get everything in your database in sync with prisma and get your data back as well.
like image 162
Obi N Avatar answered Aug 06 '26 20:08

Obi N