I have multiple DbContext
s in a C# project and I'm trying to enable migrations. When I specify the full command, i.e.:
Enable-Migrations -ContextTypeName Models.Account.AccountDetailDbContext
A migrations folder is created, with the configuration class, but 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.
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 is making the migration fail, but I can't tell what it is.
I solved this by adding EntityFrameworkCore\
before Add-Migration
, i.e. the final statement was:
EntityFrameworkCore\Add-Migration
After give a name for your new migration.
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.
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