diff --git a/EstusShots.Server/Services/EstusShotsContext.cs b/EstusShots.Server/Services/EstusShotsContext.cs index 812be06..181e324 100644 --- a/EstusShots.Server/Services/EstusShotsContext.cs +++ b/EstusShots.Server/Services/EstusShotsContext.cs @@ -7,7 +7,6 @@ namespace EstusShots.Server.Services { public EstusShotsContext(DbContextOptions options) : base(options) { - Database.EnsureCreated(); } public DbSet Seasons { get; set; } = default!; diff --git a/EstusShots.Server/Startup.cs b/EstusShots.Server/Startup.cs index 7566fec..76fc110 100644 --- a/EstusShots.Server/Startup.cs +++ b/EstusShots.Server/Startup.cs @@ -74,6 +74,11 @@ namespace EstusShots.Server app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); + + // Open a scope and create the database, if necessary + using var scope = app.ApplicationServices.GetRequiredService().CreateScope(); + using var context = scope.ServiceProvider.GetService(); + context.Database.EnsureCreated(); } } } \ No newline at end of file