Fix issue with Unable to create a 'DbContext' of type 'AppDbContext'
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
/// <summary>
|
||||
/// Creates <see cref="AppDbContext"/> for EF tools and migration bundles without
|
||||
/// running <c>Program.cs</c> (JWT and other runtime config are not available there).
|
||||
/// <c>./migrate-api --connection</c> still overrides the connection at apply time.
|
||||
/// </summary>
|
||||
public sealed class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
|
||||
{
|
||||
public AppDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var connectionString =
|
||||
Environment.GetEnvironmentVariable("ConnectionStrings__DefaultConnection")
|
||||
?? "Host=127.0.0.1;Database=vigilcare;Username=postgres;Password=postgres";
|
||||
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseNpgsql(connectionString)
|
||||
.Options;
|
||||
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user