Error: The name is used by an existing migration
Asked Answered
T

7

13

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.

Trope answered 13/3, 2020 at 9:22 Comment(4)
Check into the project structure through File Explorer. There might be some classes/files that you would need to delete manually so that you can redo your migration.Homunculus
Checked already, there's no file or class have that name. When use add-migration Blablabla, it create a cs file with time stamp before the name "Blablabla" (Ex: 20200313092540_Blablabla), I don't see how it can be douplicated?Trope
I see your point, did you check the DB as well? If I recall a migration table is created as well.Homunculus
Checked in DB, table EFMigrationsHistory, there's no record in MigrationId column that have that name. So confuse...Trope
P
17

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

Polenta answered 7/6, 2020 at 8:38 Comment(1)
Only rebuild worked for me with .net core 3.1. ThanksCopulative
P
6

Try to build your application after removing migration:

dotnet ef migrations add YourMigration
dotnet ef migrations remove
dotnet build
dotnet ef migrations add YourMigration
Phidippides answered 13/3, 2020 at 10:0 Comment(1)
I right clicked on a Solution and choose rebuild. What's the different between using dotnet build and regular build?Trope
I
3

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

Indelicacy answered 19/2, 2021 at 13:24 Comment(0)
C
2

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

Convolvulus answered 24/9, 2020 at 13:57 Comment(0)
P
1

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.

Punjabi answered 7/6, 2020 at 9:56 Comment(0)
H
0

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

Hippopotamus answered 7/6, 2020 at 9:0 Comment(0)
S
0

Build -> Clean Solution does the job.

Sustain answered 16/10, 2020 at 11:56 Comment(1)
no it doesn't do the jobComprise

© 2022 - 2024 — McMap. All rights reserved.