I have multiple dbcontexts in a C# project and I'm trying to enable migrations, when I specify the full command ie:
"Enable-Migrations -ContextTypeName Models.Account.AccountDetailDbContext"
A migrations folder is created, with the configuration class
I then get a message:
"Checking if the context targets an existing database..."
And then
"The migrations configuration type 'Portal.WebUI.Migrations.Configuration' was not be found in the assembly 'Portal.WebUI'."
Even though it has just created the file it can't find it.
Can anyone help on this please?
I have the correct project selected in the Package Manager Console
I have tried the command using -verbose, but it gives no additional information
If I copy the dbcontexts and classes into a new project then it all works, so it must be something in this existing project that it making the migration fail, but I can't tell what it is.
Thanks in advance for any answers
I managed to resolve this by uninstalling the EF nuget package and then reinstalling it.
Rather annoying...but I hope it helps someone else.
Another possible issue worth checking: is your project signed? As I just discovered, this problem can also eventuate if the assembly is signed with a strong name key file. Part of the EntityFramework tool kit is migrate.exe which is called during the migration process. It appears if the assembly is signed, this application can't find the configuration type.
Solution seems to be <Project> → Properties → Signing: untick "Sign the assembly", at least while performing migration tasks. Tick it back when you're done.
I also had this issue because of a spelling mistake in a namespace
I was facing the same issue. What I found was that in my project name, "-"
was included as "abc-xyz"
. I deleted my project and recreated it as "abcxyz"
and it worked. Don't rename the project—you have to rename it at every reference. In this case, first uninstall EF and rename it, then install EF again.
I faced this problem. My solution:
Exit visual studio
Open your project again on visual studio
Rebuild solution
Then the error removed. And I can run the command.
After you run Enable-Migrations
and the Configuration file is created, rebuild the project and run Enable-Migrations -Force
again.