My program can’t find localhost after adding migrations, i’ve already connected to docker and in docker logs there is line “server started 2024-08-01 23:20:46 CREATE DATABASE”.
using Microsoft.EntityFrameworkCore;
using WebApiLearning.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
});
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
dbContext.Database.Migrate();
}
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.Run();
I checked json.settings and docker-compose files and they seem correct
New contributor
sunday is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.