❔ error: Unable to create a 'DbContext' of type '' ". When adding migration to MySQL database
hi there!
im just starting a webapi project and i wanted to use a mysql docker container and go code-first using the entity framework, however, im having troubles trying to add migrations, im getting the following error
in theory, i have my dbcontext declared
and my program builds with it
could someone give me a hand? what am i missing?
im just starting a webapi project and i wanted to use a mysql docker container and go code-first using the entity framework, however, im having troubles trying to add migrations, im getting the following error
Unable to create a 'DbContext' of type ''. The exception 'Method not found: 'Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.Clone(Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingInfo ByRef)'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728Unable to create a 'DbContext' of type ''. The exception 'Method not found: 'Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.Clone(Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingInfo ByRef)'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728in theory, i have my dbcontext declared
namespace Mama.Data {
public class AppDbContext : DbContext {
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<User> Users { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderStatus> OrderStatuses { get; set; }
public DbSet<OrderedProduct> OrderedProducts { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Service> Services { get; set; }
public DbSet<UserRole> UserRoles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
}
}
}namespace Mama.Data {
public class AppDbContext : DbContext {
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public DbSet<User> Users { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderStatus> OrderStatuses { get; set; }
public DbSet<OrderedProduct> OrderedProducts { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Service> Services { get; set; }
public DbSet<UserRole> UserRoles { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
}
}
}and my program builds with it
var builder = WebApplication.CreateBuilder(args);
{
var dbConn = builder.Configuration["Database:Connection"];
var dbVersion = new MySqlServerVersion(new Version(8, 1));
builder.Services.AddDbContext<AppDbContext>(ctx => ctx
.UseMySql(dbConn, dbVersion)
// TODO: Remove on prod
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
);
...
}var builder = WebApplication.CreateBuilder(args);
{
var dbConn = builder.Configuration["Database:Connection"];
var dbVersion = new MySqlServerVersion(new Version(8, 1));
builder.Services.AddDbContext<AppDbContext>(ctx => ctx
.UseMySql(dbConn, dbVersion)
// TODO: Remove on prod
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
);
...
}could someone give me a hand? what am i missing?