Efcore: The last removed migration name cannot be reused

Created on 14 Apr 2016  Â·  4Comments  Â·  Source: dotnet/efcore

rc2 latest dev bits

The following migration sequence does not work:

dotnet ef migrations add Initial
dotnet ef migrations remove
dotnet ef migrations add Initial

The last line throws:

System.InvalidOperationException: The name 'Initial' is used by an existing migration.
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The name 'Initial' is used by an existing migration.

I can mitigate the problem by making any change in one of the project files, which causes the project to be rebuild, right before the second dotnet ef migrations add Initial call.

Btw. the following sequence does work:

dotnet ef migrations add Initial
dotnet ef migrations add SecondMigration
dotnet ef migrations remove
dotnet ef migrations add SecondMigration

Most helpful comment

@rmja what happens if you build after removing?

dotnet ef migrations add Initial
dotnet ef migrations remove
dotnet build
dotnet ef migrations add Initial

All 4 comments

@rmja what happens if you build after removing?

dotnet ef migrations add Initial
dotnet ef migrations remove
dotnet build
dotnet ef migrations add Initial

@natemcmaster that works. That is what the "changing any file" implicitly means☺

The source of the issue is dotnet-build. This is a duplicate of https://github.com/dotnet/cli/issues/1440. I'll leave this open to track on our side.

Was this page helpful?
0 / 5 - 0 ratings