迁移与 dotnet ef 错误:无法创建类型为"MyClass"的对象



我正试图使用dotnet ef migrations进行迁移,添加MyMigration,但shell返回错误:无法创建类型为"AuthDbContext"的对象。有关设计时支持的不同模式,请参阅https://go.microsoft.com/fwlink/?linkid=851728.

这是我的AuthDbContext.cs文件:

using Auth.Data.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Auth.Data
{
public class AuthDbContext : IdentityDbContext<User>
{
private readonly string connStr;
//public DbSet<User> Users { get; set; }
public AuthDbContext(DbContextOptions<AuthDbContext> options) : base(options)  //string connStr)
{
//this.connStr = connStr;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// string connStr = "";
// connStr = "";
// if (!optionsBuilder.IsConfigured)
// {
//    optionsBuilder
//        .EnableSensitiveDataLogging(true)
//        .UseSqlServer(connStr);
// }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("auth");
//modelBuilder.Entity<User>().HasKey(p => new { p.User_id });
base.OnModelCreating(modelBuilder);
}


}
}

有人能帮我理解吗?谢谢

您忘记添加此行

base.OnConfiguring(optionsBuilder);

EF Core无法完成上下文实例化。

相关内容

最新更新