FrankO
FrankO

Reputation: 2562

Entity Framework Migration "No connection string named 'DefaultConnection' could be found..."

I have been working with MVC5 and Entity Framework 6 for the past few months. I have separated my main models/business logic and "Migrations" to a separate assembly and referenced it in my web application. Migrations have been working just fine.

Today I ran "Update-database" and I get "No connection string named 'DefaultConnection' could be found in the application config file."

The 'DefaultConnection' is STILL in my web.config file. If I copy the section to the project where the Migrations are located, it works again. If I remove the section, it throws that error. I don't know what might have changed.

The only thing I did since yesterday was run "Disk Cleanup" to clear up space on my HD.

Upvotes: 16

Views: 6474

Answers (2)

FrankO
FrankO

Reputation: 2562

Okay. After some obscure Google searches I found the answer. Apparently my project containing the Migration code was set as the "Startup Project".

After resetting my web application as the Startup Project (and making sure the 'Default Project' in the Package Manager is set to my Migrations project), it started working again!

Problem solved!

Upvotes: 42

Ilya Sulimanov
Ilya Sulimanov

Reputation: 7856

Make sure that the execution of a command from Nuget console you choose the right project enter image description here

Upvotes: 2

Related Questions