C
C#16mo ago
Kris

❔ 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
Kris
KrisOP16mo ago
My appsettings and appsettings.Development.json have the same content
Kris
KrisOP16mo ago
undisputed world champions
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 catthinking
Kris
KrisOP16mo ago
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 results
Kris
KrisOP16mo ago
This is my file structure @icebear42
Kris
KrisOP16mo ago
I also tried adding the connection string directly in Program.cs via below and still getting the same error
phaseshift
phaseshift16mo ago
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
Kris
KrisOP16mo ago
Ahh will try that
Kris
KrisOP16mo ago
I threw up on the verbose flag this is giving me clues
Kris
KrisOP16mo ago
Adding the connection string directly into the method worked ughh.. The mystery continues!
Kris
KrisOP16mo ago
The connection string is right, I think the location of the appconfig is throwng it off
blueberriesiftheywerecats
You dont need OnConfiguring, you need to pass through ctor smth like IDbContextOptions/IDbContextOptionsBuilder(i forgor)
Accord
Accord16mo ago
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.
Stage
Stage2mo ago
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.)
Want results from more Discord servers?
Add your server