question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrate function fails silently if Microsoft.EntityFrameworkCore.Relational package is not installed.

See original GitHub issue

Not sure where, if this is an error, belongs. So I created it here.

The context.Database.Migrate(); method appears to fail silently if the project that defines the context and corresponding entities does not have the Microsoft.EntityFrameworkCore.Relational nuget package installed. The database does get created, but none of the migrations get applied.

However, if I run the Update-Database call via the Package Manager Console the database gets created and the migration gets applied correctly.

Initially, I thought it was an issue with MigrationAssembly not being correct for some reason, so after explicitly declaring the MigrationAssembly in the OnConfiguring method I was suddenly being presented with the following error (when before there was no errors being presented.)

Could not load file or assembly 'Microsoft.EntityFrameworkCore.Relational, Version=5.0.9.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

Noticing that I was missing this nuget package in the context project, I added in said package and removed the explicit MigrationAssembly declaration. Then the migrations were being applied correctly.

Include provider and version information

EF Core version: 5.0.9 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL Target framework: .NET 5.0 Operating system: Windows 10 x64 IDE: Visual Studio 2019 16.3

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Sep 15, 2021

@DizzyDeveloper we agree that there’s an issue here (silent failure), and that we need to investigate; but as you say, this isn’t the highest-priority problem, so it is currently in the backlog.

0reactions
DizzyDevelopercommented, Sep 13, 2021

Hi @roji, Thanks for that 😃

However, sorry there is an however, I probably more concerned about the symptom rather than the cause. As mentioned above I was also able to resolve it by just including the package.

There does not appear to be any indication that this is a build issue. Just an odd silent “failure” in the Migrate call. Considering that there are no build errors, I am able to generate migrations to my hearts content, I can even successfully apply the migrations manually using the Update-Database call, and against a pre-existing DB I can happily run EF queries.

The only way that I was able to detect that there was a build related issue was when I added the opt.MigrationAssembly ("..."), that then cause the Migrate to throw that error that I mentioned above about the missing assembly? Shouldn’t the Migrate function be indicating that “hey something is a miss here” even without opt.MigrationAssembly being needed. Caveat I don’t know if it is actually that function or that function triggers some other validation that can happen without that needing to be specified.

Those were just my final thoughts, I suspect this is probably a reasonably niche issue. So if you want to close this you can.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The EntityFramework package is not installed on project
This error can happen if the Entity Framework command's target project is unloaded in the Visual Studio solution (i.e. if you'd previously right ......
Read more >
'EntityFramework.Core.Tools' nuget package installation error
While installing the package Microsoft.EntityFrameworkCore.Tools for using EF in my project using Nuget, I'm persistently running into the ...
Read more >
Breaking changes in EF Core 7.0 (EF7)
This is a severe breaking change in the Microsoft.Data.SqlClient package. There is nothing that can be done in EF Core to revert or...
Read more >
Getting compile error when trying to add migrations
add-migration InitialMigration. I get the following error. The EntityFramework package is not installed on project 'Concierge.Dal'.
Read more >
Breaking changes in EF Core 6.0
Complete list of breaking changes introduced in Entity Framework Core 6.0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found