Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert database in Entity Framework code-first

I made a in my model and updated database using

Add-Migration sdfgfsd
Update-Database

Now I found the change I just made is not necessary.

I would like do revert both code and database.

How can I do this?

like image 619
Kuttan Sujith Avatar asked May 28 '15 12:05

Kuttan Sujith


People also ask

How do I rollback migration code first in Entity Framework?

How do I rollback Entity Framework Code First migration? You can also Undo/Rollback specific migrations by using the following commands: Rollback to a specific migrations. Update-Database -TargetMigration:MigrationsName.

How do I revert a database migration?

Reverting a Migration In this case, use the update-database <migration name> command to revert the database to the specified previous migration snapshot.


1 Answers

Yes - it's straightforward. Use

Update-Database -TargetMigration:zzzz

Where zzzz is the name of the migration before the one you want to rollback.

EDIT You then need to delete the migration(s) after zzzz.

If you want to rollback all migrations, or if you only have one migration, use

update-database -target:0
like image 115
Peter Smith Avatar answered Oct 14 '22 09:10

Peter Smith