Answer the question
In order to leave comments, you need to log in
Why does the migration fail?
I'm trying to make a migration in RIDER, but I keep getting an error with the migration, what exactly is the problem?
Migrating I make dotnet-ef migrations add LibralyReact
an error: Unable to create an object of type 'ApplicationContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
User:
public class User:IdentityUser
{
public string Password { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
}
public sealed class ApplicationContext:IdentityDbContext<User>
{
public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
base.OnModelCreating(builder);
}
}
public static IServiceCollection InitServices(IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<ApplicationContext>(
options => options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("Libraly.Data")
));
services.AddIdentity<User, IdentityRole>().AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationContext>();
services.AddSingleton(typeof(IUnitOfWork<>), typeof(IUnitOfWork<>));
return services;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//настройка сервисов
ConfigService.InitServices(services, Configuration);
services.AddControllersWithViews();
services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; });
}
Answer the question
In order to leave comments, you need to log in
Need to create a DesignTimeContextFactory https://go.microsoft.com/fwlink/?linkid=851728
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question