首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到方法:'Void Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator..ctor(Microsoft.EntityFrameworkCore.Migrations.IMigrationsAssembly

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

Stack Overflow用户
提问于 2021-03-08 16:47:43
回答 1查看 113关注 0票数 0

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

我所有的项目都是ASP.NET Core5.0

我使用的包是:

对于DB项目:

*EntityFrameWorkCore

*EntityFrameWorkCore.Tools

*Install-Package Pomelo.EntityFrameworkCore.MySql -Version 5.0.0-alpha.2

*Microsoft.AspNetCore.Identity

*Microsoft.AspNetCore.Identity.EntityFrameworkCore

对于API项目:

*EntityFrameWorkCore.Design

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

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

到Startup.cs

代码语言:javascript
复制
    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:

代码语言:javascript
复制
{
  "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是:

代码语言:javascript
复制
public class DBAccessContext : IdentityDbContext<User>
{
    public DBAccessContext (DbContextOptions<DBAccessContext> options) : base(options)
    {

    }
}

用户所在位置

代码语言:javascript
复制
public class User : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-08 19:33:37

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66526701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档