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.
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.
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.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With