fix: use EnsureCreated instead of Migrate to handle missing initial migration

This commit is contained in:
2026-06-09 01:52:29 +03:30
parent 2c87b5bd49
commit 7e54818332

View File

@@ -177,11 +177,13 @@ builder.Services.AddSwaggerGen(c =>
var app = builder.Build();
// Apply pending migrations automatically on startup
// Ensure database is created and apply pending migrations
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ComplexDBContext>();
dbContext.Database.Migrate();
// EnsureCreated creates all tables from the model if they don't exist,
// while Migrate applies any pending migrations on top.
dbContext.Database.EnsureCreated();
// Seed essential reference data and test data
await DataSeeder.SeedAsync(dbContext);
}