I am trying to deploy my Web API to an Azure App Service using Visual Studio 2022, however when I try to apply the migrations, it is not discovering the connection string although it discovers the database context:
This is the code of my database context class:
namespace MyPortfolioWebAPI.Data
{
public class MyPortfolioContext:DbContext
{
public MyPortfolioContext(DbContextOptions<MyPortfolioContext> options) : base(options)
{
}
public DbSet<Emails> Emails { get; set; } = null!;
public DbSet<Projects> Projects { get; set; } = null!;
}
}
This is my appsettings.json
file:
It works fine on my local machine, however I am trying to publish it to Azure.
CodePudding user response:
Change your appsettings.json
file like below. The issue should be fixed.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"DefaultConnection": "Your_Connection_String"
},
"AllowedHosts": "*"
}
I test in my local and use .net6 project. And found builder.Configuration.GetConnectionString
can directly identify the element under the key of ConnectionStrings
.
Your code has one more layer of Data nested
, that's why it can't be read.