Error: The name is used by an existing migration

Viewed 9658

Recently I run add-migration command, and I have some mistakes, so I run remove-migration to undo it. But when I run add-migration again, it said: The name 'blablabla' is used by an existing migration. How to fix this. I already double check Migration folder, there is no migration that have that name.

7 Answers

Delete bin and obj folder in the src of your project, rebuild and It should allow you to add migrations with the same name. This works for me.

It seems that they are cached in the bin and obj folder and when you try to add a new migration with the same name it checks those folders and throws you the error message.

Tested on .net core 2.2

Try to build your application after removing migration:

dotnet ef migrations add YourMigration
dotnet ef migrations remove
dotnet build
dotnet ef migrations add YourMigration

If you have access to your database, Go to the Database and Remove that Last Migration you add in the migration table. Then it should work again without any problem.

Check the "Data" folder. There are migrations there also. Delete the folder, re-run the build and should work.

Build -> Clean Solution does the job.

Check the \Migrations folder, delete the 'blala' name, both .cs. and Designer.cs. Run the add-migration again , should work.

maybe its exclude from the project. check TFS or file explorer.

Related