Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: The name is used by an existing migration

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.

like image 435
KaMaHe Avatar asked Mar 13 '20 09:03

KaMaHe


People also ask

How do I update an existing migration database?

Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.

Why add migration is not working?

Add-Migration - The Term 'Add-Migration' Is Not Recognized After creating models and context class, we nomally add migration to initialize the database. The error occurs sometimes while adding migration in asp.net core, entity framework with code first approach because of some missing library.


Video Answer


2 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

like image 195
ppavlov Avatar answered Sep 22 '22 02:09

ppavlov


Try to build your application after removing migration:

dotnet ef migrations add YourMigration
dotnet ef migrations remove
dotnet build
dotnet ef migrations add YourMigration
like image 35
StepUp Avatar answered Sep 23 '22 02:09

StepUp