How to disable porting in ASP.NET Core with EF Core

When I run PM> Remove-Migration -context BloggingContext in VS2015 using an ASP.NET Core project using EF Core, I get the following error:

 System.InvalidOperationException: The migration '20160703192724_MyFirstMigration' 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. at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force) at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.RemoveMigration(String contextType, Boolean force) at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsRemoveCommand.<>c__DisplayClass0_0.<Configure>b__0() at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) The migration '20160703192724_MyFirstMigration' 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. 

How can I remove it? I am using the latest version of ASP.NET Core 1.0, EF Core and VS2015 Update 3.

+131
c # asp.net-core visual-studio-2015 .net-core entity-framework-core
Jul 04 '16 at 21:29
source share
14 answers

Using:

CLI

> dotnet ef database update <previous-migration-name>

Package Manager Console

PM> Update-Database <previous-migration-name>

Example:

PM> Update-Database MyInitialMigration

Then try to delete the last migration.

Removing a migration without updating the database does not work because you applied the changes to the database.

If you use PMC, try: PM> update-database 0 This will destroy the database and allow you to remove the migration snapshot in your solution.

+151
Jul 05 '16 at 7:44
source share

To completely remove all migrations and start all over again, do the following:

 dotnet ef database update 0 dotnet ef migrations remove 
+101
Nov 27 '16 at 18:22
source share

You can still use the Update-Database command.

 Update-Database -Migration <migration name> -Context <context name> 

However, judging by the name of your migration, I assume this is the first migration, so the team may not work. You must delete the entry from the __MigrationHistory table in your database, and then run the Remove-Migration command again. You can also delete the migration file and just start over.

+49
Jul 05 '16 at 9:29
source share

To undo the last applied migration, you should (package manager console command):

  1. Cancel migration from database: PM> Update-Database <prior-migration-name>
  2. Delete the migration file from the project (or it will be applied again in the next step)
  3. Update Model Snapshot: PM> Remove-Migration

UPD : The second step does not seem to be required in recent versions of Visual Studio (2017).

+24
May 03 '18 at 10:26
source share

You can simply configure the migration by value

  Update-Database -Migration:0 

Then go and delete him

  Remove-Migration 
+22
Mar 19 '18 at 9:05
source share

To cancel a specific migration (s) :

 dotnet ef database update <previous-migration-name> or PM> Update-Database -Migration <previous-migration-name> 

To cancel all migrations :

 dotnet ef database update 0 or PM> Update-Database -Migration 0 

To remove the last migration:

 dotnet ef migrations remove or PM> Remove-Migration 

To undo and delete the last migration:

 dotnet ef migrations remove --force or PM> Remove-Migration -Force 
+15
Mar 24 '19 at 11:07
source share

In order not to "use" the most (recent?) Migration after it has already been applied to the database:

  • Open the SQL Server Object Browser (View β†’ "SQL Server Object Browser")
  • Go to the database associated with your project by turning the small triangles to the side.
  • Expand Tables
  • Locate the table named "dbo._EFMigrationsHistory".
  • Right-click on it and select "View Data" to see the entries in Visual Studio.
  • Delete the line that matches your migration that you want to delete (say yes to the warning if prompted).
  • Run "dotnet ef migrations remove" again in the command window in the directory with the project.json file. Alternatively, run the Delete-Migration command in the Package Manager console.

Hope this helps and applies to any migration in the project ... I checked this only for the most recent migration ...

Happy coding!

+13
Dec 02 '16 at 20:36
source share

In the package manager console:

Update-Database Your_Migration_You_Want_To_Revert_To

More options and explanations on how to cancel the migration can be found here.

+8
Feb 16 '18 at 12:53
source share

In general, if you use the package manager console, the correct way to remove a specific migration is to refer to the migration name.

 Update-Database -Migration {Name of Migration} -Context {context} 

Another way to delete the last migrated migration according to the documents is to use the command:

 dotnet ef migrations remove 

This command should be executed from the developer's command line ( how to open the command line ) inside your solution directory.

For example, if your application is located inside the name "Application" and is located in the c: \ Projects folder. Then your path should be:

 C:\Projects\Application 
+7
Nov 04 '17 at 21:28
source share

You must delete the migration entry '20160703192724_MyFirstMigration' from the _EFMigrationsHistory table.

Otherwise, this command will delete the Migration folder and the Delete Migration folder:

  > remove-migration -force 
+6
Jan 14 '19 at 12:49
source share

To disable porting in EF Core 1.0, use the command:

Updating the dotnet ef database {stream_name}

Use the name of the migration migration to which you want to save your changes. A list of migration names can be found using:

dotnet ef jump list

+2
Nov 20 '17 at 15:32
source share
 var context = serviceProvider.GetRequiredService<ApplicationDbContext>(); var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>(); var roleManaget = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>(); await context.Database.EnsureDeletedAsync(); 
0
Mar 08 '19 at 4:26
source share

1. Find the table "dbo._EFMigrationsHistory", then delete the migration record that you want to delete. 2. Run "delete-migration" in PM (Package Manager Console). It works for me.

-one
Apr 11 '18 at 7:45
source share

first run the following command:

 PM>update-database -migration:0 

and then run this:

 PM>remove_migration 

Finish

-one
Aug 19 '19 at 7:37
source share



All Articles