Search code examples
c#mysqlapiasp.net-corepomelo-entityframeworkcore-mysql

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


I am creating a Solution with 3 projects, one for the EF Core, one for the Database and the last one is for the API. The API is the startup project. I am trying to build a migration from the database project. This Migration is supposed to create the Identity's package built-in User tables. However, I keep receiving the error above.

All my projects are ASP.NET Core 5.0

The Packages I am using are:

For the DB Project:

*EntityFrameWorkCore

*EntityFrameWorkCore.Tools

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

*Microsoft.AspNetCore.Identity

*Microsoft.AspNetCore.Identity.EntityFrameworkCore

For the API Project:

*EntityFrameWorkCore.Design

I have referenced the DB project in the API startup Project

In the API Project I did the following changes:

To the 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" });
        });
    }

To the 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"
  }
}

And finally my DBAccessContect is:

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

    }
}

where user is

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

Solution

  • I solved the error by down-graded all my framework packages from the 6.0.0 preview version to the 5.0.3 stable verion