They serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs
db pushuses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. Thedb pushcommand:
Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.
By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke
prisma generate.If
db pushanticipates that the changes could result in data loss, it will:
- Throw an error
- Require the
--accept-data-lossoption if you still want to make the changesNote:
db pushdoes not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.
The prisma migrate dev is used in you local environment, as explained in the docs
migrate devis a development command and should never be used in a production environment.This command:
- Replays the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema)
- Applies pending migrations to the shadow database (for example, new migrations created by colleagues)
- Generates a new migration from any changes you made to the Prisma schema before running
migrate dev- Applies all unapplied migrations to the development database and updates the
_prisma_migrationstable- Triggers the generation of artifacts (for example, the Prisma Client)
The
migrate devcommand will prompt you to reset the database in the following scenarios:
- Migration history conflicts caused by modified or missing migrations
- The database schema has drifted away from the end-state of the migration history
If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.
Answer from Daniel Olavio Ferreira on Stack OverflowThey serve two different environments. The prisma db push is not to be used in your production environment, as stated in the docs
db pushuses the same engine as Prisma Migrate to synchronize your Prisma schema with your database schema, and is best suited for schema prototyping. Thedb pushcommand:
Introspects the database to infer and executes the changes required to make your database schema reflect the state of your Prisma schema.
By default, after changes have been applied to the database schema, generators are triggered (for example, Prisma Client). You do not need to manually invoke
prisma generate.If
db pushanticipates that the changes could result in data loss, it will:
- Throw an error
- Require the
--accept-data-lossoption if you still want to make the changesNote:
db pushdoes not interact with or rely on migrations. The migrations table will not be updated, and no migration files will be generated.
The prisma migrate dev is used in you local environment, as explained in the docs
migrate devis a development command and should never be used in a production environment.This command:
- Replays the existing migration history in the shadow database in order to detect schema drift (edited or deleted migration file, or a manual changes to the database schema)
- Applies pending migrations to the shadow database (for example, new migrations created by colleagues)
- Generates a new migration from any changes you made to the Prisma schema before running
migrate dev- Applies all unapplied migrations to the development database and updates the
_prisma_migrationstable- Triggers the generation of artifacts (for example, the Prisma Client)
The
migrate devcommand will prompt you to reset the database in the following scenarios:
- Migration history conflicts caused by modified or missing migrations
- The database schema has drifted away from the end-state of the migration history
If you have any other question regarding this, there is this comparison in the docs explaining when to use one or the other.
- Prisma db push syncs (and formats) your prisma schema to that of your database schema.
- While prisma migrate dev "command automatically generates SQL migration files (saved in /prisma/migrations) and applies them to the database".
The main difference between both is the generation of the migration files.
I ran `prisma db push`, and now when I run `prisma migrate dev` it prompts me to reset the database. How do I migrate without resetting and losing the data?
need to run db push twice in order to apply changes
Switch to migrations after db push
npx prisma db push -> dangerous
Hey guys, i am writing this is pain but i am a startup and we had around 500+ data, i was pushing a change in database and got my data erased. I am stupid that i didnt do the migrations and is free version. I have mailed the supabase community but i would like your help too.