efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF7 Migration Rollback?

Open WillBaldwin opened this issue 11 years ago • 9 comments

using EntityFramework 7.0.0.-beta1

Is it possible to roll back migrations yet? If so, I am assuming that it is a "k ef migration" command?

WillBaldwin avatar Jan 24 '15 17:01 WillBaldwin

Looks like the PM command is remove-migration https://github.com/aspnet/EntityFramework/blob/dev/src/EntityFramework.Commands/tools/EntityFramework.psd1

ErikEJ avatar Jan 25 '15 07:01 ErikEJ

Remove-Migration (or k ef migration remove) is only about removing unapplied migrations from your project.

To rollback (or unapply) migrations from the database, use Apply-Migration TargetMigration (or k ef migration apply targetMigration) where TargetMigration is the name of the migration you want to rollback to.

To rollback all migrations, use Apply-Migration 0.

bricelam avatar Jan 25 '15 18:01 bricelam

k ef migration apply 0 works !! Thank you so much!

WillBaldwin avatar Jan 26 '15 15:01 WillBaldwin

that 0 should be documented!!

Bartmax avatar Apr 18 '15 11:04 Bartmax

@Bartmax I'll make sure it gets done as part of #578

bricelam avatar Apr 19 '15 02:04 bricelam

Excellent! thanks.

Bartmax avatar Apr 19 '15 22:04 Bartmax

Hi. I'm not sure if this is the right place to post question. Excuse-me if I'm wrong.

I am trying to unapply a migration and I'm getting the following message:

The migration '20161108115840_CriaTabelaUnidade' has already been applied to the database. Unapply it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.

Next, I'm trying to unapply this migration. But the command Apply-Migration isn't recognized.

And I didn't find any reference to this command in the docs: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

Is there another way to unapply migrations?

adrianorc avatar Nov 16 '16 17:11 adrianorc

@adrianorc To revert (or unapply) a migration from the database use Update-Database ThePreviousMigration. To remove (or delete) a migration from the project, use Remove-Migration.

bricelam avatar Nov 16 '16 17:11 bricelam

@bricelam Worked. Thank you!

adrianorc avatar Nov 16 '16 17:11 adrianorc