dotnet ef "No migrations configuration" / Migrations Fail in CI
A dotnet ef migrations / database update / migrations script step failed because EF Core could not build the DbContext at design time - a missing tool, design-time factory, or wrong startup project in CI.
What this error means
The EF step fails with "Unable to create a DbContext", "No project was found", or "No design-time services were found", and no migration runs. It commonly appears when CI lacks the dotnet-ef tool or the context needs runtime config it does not have at design time.
Unable to create a 'DbContext' of type 'AppDbContext'. The exception 'Value cannot be
null. (Parameter 'connectionString')' was thrown while attempting to create an instance.Common causes
dotnet-ef tool not restored in CI
The dotnet ef command is a local/global tool. If dotnet tool restore was not run, the command (or the right version) is missing.
DbContext needs runtime config at design time
The context resolves its connection string from app config/secrets that are not present at design time in CI, so EF cannot instantiate it without a design-time factory.
How to fix it
Restore the EF tool and target the right projects
Restore the local tool and point EF at the correct startup and migrations projects.
dotnet tool restore
dotnet ef migrations script --idempotent \
--project src/Data --startup-project src/Api -o migrate.sqlAdd a design-time DbContext factory
Provide an IDesignTimeDbContextFactory so EF can build the context without full runtime config.
public class AppDbContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
public AppDbContext CreateDbContext(string[] args)
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseNpgsql(Environment.GetEnvironmentVariable("ConnectionStrings__Default"))
.Options;
return new AppDbContext(options);
}
}How to prevent it
- Run
dotnet tool restorebefore anydotnet efstep in CI. - Provide an
IDesignTimeDbContextFactoryfor contexts that need runtime config. - Prefer
migrations script --idempotentto apply schema changes deterministically in pipelines.