Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - The migrations configuration type was not be found in the assembly

I have multiple DbContexts 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.

like image 638
user3187775 Avatar asked Aug 17 '16 16:08

user3187775


3 Answers

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.

like image 123
user14034691 Avatar answered Sep 30 '22 18:09

user14034691


I faced this problem. My solution:

  1. Exit visual studio

  2. Open your project again on visual studio

  3. Rebuild solution

Then the error removed. And I can run the command.

like image 41
Kabir Hossain Avatar answered Sep 30 '22 20:09

Kabir Hossain


After you run Enable-Migrations and the Configuration file is created, rebuild the project and run Enable-Migrations -Force again.

like image 27
Dragos Bursacovschi Avatar answered Sep 30 '22 20:09

Dragos Bursacovschi