❔ Host Can't be Null error when trying to run db migration using postgres
I'm pretty sure this is a id10t issue here. I have added appsettings.json and appsettings.Development.json in all of my directories because I think my program is not referencing the right appsettings.json, however when I did I am still getting the error.
14 Replies
My appsettings and appsettings.Development.json have the same content
it seems like you don't have a appsettings.json in your Web-project
that's the one that counts
not sure if it makes sense having appsettings.json in library-project
Idk if this helps but I am running
dotnet ef database update
in my Helpers directory. That's where my Data Context.cs is. I readded appsettings.json and apsettings.Development.json in the Web ( realized it's missing in that screenshot ) and am getting the same resultsThis is my file structure @icebear42
I also tried adding the connection string directly in Program.cs via below and still getting the same error
I think since you split the context out from the web host you need to specify extra stuff in the command
e.g. if you run from the the context location you need to specify the other project (-p flag)
vice versa would need the -c flag to specify the name of the context as well?
But not really sure - just reading chat gpt
Ahh will try that
I threw up on the verbose flag this is giving me clues
Adding the connection string directly into the method worked ughh.. The mystery continues!
The connection string is right, I think the location of the appconfig is throwng it off
You dont need OnConfiguring, you need to pass through ctor smth like IDbContextOptions/IDbContextOptionsBuilder(i forgor)
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Reviving this just to tell anyone who stumbles across this like I did: The only thing that fixed this for me was to remove my design-time DbContextFactory implementation, which had a default constructor. A tell-tale sign you have the same issue is to run
dotnet ef database update
with a valid connection string as a CLI argument: --connection "<connection str>"
. The key is to get rid of any design-time factories / ways a DbContext
can be instantiated without valid credentials. Hope this helps! (This assumes you have an otherwise valid configuration etc.)