Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reverse for Update-Database (used in Package Manager Console)?

Tags:

I have been changing my domain classes and executed Update-Database in the Package Manager Console, After i realized that need to add an index and need to down-grade to the previous state. what is the proper command to down-grade one step in migration?

like image 673
Ehsan Zargar Ershadi Avatar asked Nov 16 '13 16:11

Ehsan Zargar Ershadi


People also ask

What happens when ADD-migration command is executed in the NuGet Package Manager console?

Add-Migration Adds a new migration. Remove-Migration Removes the last migration. Scaffold-DbContext Scaffolds a DbContext and entity type classes for a specified database. Script-Migration Generates a SQL script from migrations.

How do I delete migration after update-database?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.

How do I remove migration from Package Manager console?

To revert the last applied migration you should (package manager console commands): Revert migration from database: PM> Update-Database <prior-migration-name> Remove migration file from project (or it will be reapplied again on next step) Update model snapshot: PM> Remove-Migration.


1 Answers

Update-Database has a TargetMigration parameter that you can use to update to a particular migration. You can use that to upgrade or downgrade.

Update-Database –TargetMigration PreviousMigrationName 
like image 142
Matt Ward Avatar answered Oct 22 '22 14:10

Matt Ward