fix: use EnsureCreated instead of Migrate to handle missing initial migration
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user