0

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; } } 
4
  • The migration only needs to be performed when the database changes and not everytime the application is run. The migration should be performed in the database project and not in the API. I would either manually do the migration or create a new project based on the database project that only does the migration. Commented Mar 8, 2021 at 9:11
  • the migration I created was the very first migration and I made sure to select the db project Commented Mar 8, 2021 at 9:13
  • Make sure the configuration change is in the namespace for the database project and not in the api project. You may also need to rebuild all projects if you upgraded the version of net/core. It looks like you are not referencing all the libraries in all three project so some libraries are missing when you compile. Adding more libraries may end up with duplicate definitions which may be harder to solve. Commented Mar 8, 2021 at 9:23
  • What do you mean by "Make sure the configuration change is in the namespace for the database project and not in the api project"????? Commented Mar 8, 2021 at 9:44

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

EF Core providers are only compatible with the major version they have been written for. So Pomelo 5.0.0 is only compatible with EF Core 5.x.y.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.