未找到方法:'Void Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator..ctor(Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly

Method not found: 'Void Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator..ctor(Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly

我正在创建一个包含 3 个项目的解决方案,一个用于 EF Core,一个用于数据库,最后一个用于 API。 API 是启动项目。我正在尝试从数据库项目构建迁移。此迁移应该创建身份包的内置用户表。但是,我一直收到上面的错误。

我所有的项目都是ASP.NETCore 5.0

我使用的包是:

对于数据库项目:

*EntityFrameWorkCore

*EntityFrameWorkCore.Tools

*安装包 Pomelo.EntityFrameworkCore.MySql - 版本 5.0.0-alpha.2

*Microsoft.AspNetCore.Identity

*Microsoft.AspNetCore.Identity.EntityFrameworkCore

对于 API 项目:

*EntityFrameWorkCore.Design

我在API启动项目中引用了DB项目

在 API 项目中,我做了以下更改:

到Startup.cs

    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)
    {
        //To Connect to MySQL:
        string mySqlConnectionStr = Configuration.GetConnectionString("DefaultConnection");
        services.AddDbContextPool<DBAccessContext>(options => options.UseMySql(mySqlConnectionStr, ServerVersion.AutoDetect(mySqlConnectionStr)));

        services.AddControllers();
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "Wasel.API", Version = "v1" });
        });
    }

到appsetting.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  //Connection String for MySQL
  "ConnectionStrings": {
    "DefaultConnection": "server=localhost; port=3306; database=my_DB; user=root; password=123456; Persist Security Info=False; Connect Timeout=300"
  }
}

最后我的 DBAccessContect 是:

public class DBAccessContext : IdentityDbContext<User>
{
    public DBAccessContext (DbContextOptions<DBAccessContext> options) : base(options)
    {

    }
}

用户所在的位置

public class User : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

我通过将所有框架包从 6.0.0 预览版降级到 5.0.3 稳定版解决了这个错误