Migrate function fails silently if Microsoft.EntityFrameworkCore.Relational package is not installed.
See original GitHub issueNot 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
@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.
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 theMigrate
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 withoutopt.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.