I have a pretty basic migration file. I'm executing dotnet ef database update --verbose
in the Package Manager Console window and nothing is getting generated in SQL Server.
The final lines of output in the Package Manager Console window is shown below:
Finding design-time services for provider Microsoft.EntityFrameworkCore.SqlServer...
Using design-time services from provider Microsoft.EntityFrameworkCore.SqlServer.
Finding design-time services referenced by assembly BM.Server.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly BM.Server...
No design-time services were found.
Done.
Here is what my code looks like and adding and removing migrations work. It's just trying to update the database that I am having this issue.
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BMDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("BMDbConnectionString")));
}
}
public class BMDbContext : DbContext
{
public BMDbContext(DbContextOptions<BMDbContext> options) : base(options) { }
}
I also have the following nuget packages installed for the project and both dlls are in my bin directory: Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Design
These services are managed separately from EF Core's runtime services to prevent them from being deployed with your app. To override one of these services (for example the service to generate migration files), add an implementation of IDesignTimeServices to your startup project.
Microsoft.EntityFrameworkCore.Design is a DevelopmentDependency package. This means that the dependency won't flow transitively into other projects, and that you cannot, by default, reference its types. In order to reference its types and override design-time services, update the PackageReference item's metadata in your project file.
The problem is that something changed between EF Core 2.2 to 3.1 that has broken or prevented ConfigurationManager from initializing properly. Now we must take extra steps to open the configuration for app.config and web.config.
Privacy policy. Thank you. Some of the EF Core Tools commands (for example, the Migrations commands) require a derived DbContext instance to be created at design time in order to gather details about the application's entity types and how they map to a database schema.
As referenced in this article you should add the design time DbContext. Add the following class to your project:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace WebApplication8
{
public class DesignTimeBMDbContext : IDesignTimeDbContextFactory<BMDbContext>
{
public BMDbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<BMDbContext>();
// pass your design time connection string here
optionsBuilder.UseSqlServer("<connection_string>");
return new BMDbContext(optionsBuilder.Options);
}
}
}
After adding this class, EF CLI will use it for design time database creation and updates
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With