添加迁移时我遇到EF核心错误问题。这是我的代码
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Category> Categories { get; set; }
public DbSet<Subject> Subjects { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Subject>().HasKey(s => s.Id);
builder.Entity<Subject>().Property(c => c.Name)
.HasMaxLength(100)
.IsRequired();
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
我想使用nuget添加迁移但是会收到此错误
添加迁移“新” C:\应用程序\项目\教育\ SRC \ Education.Web.Admin.Frontend.App \ project.json(34,43): 警告NU1012:依赖冲突。 Microsoft.EntityFrameworkCore 1.1.1预期Microsoft.Extensions.Logging&gt; = 1.1.1但收到1.0.0在'ApplicationDbContext'上找不到无参数构造函数。添加无参数构造函数 'ApplicationDbContext'或添加一个实现 'IDbContextFactory'在同一个程序集中 'ApplicationDbContext'。
答案 0 :(得分:0)
错误消息似乎足够清楚。你的Db上下文类没有无参数构造函数。你应该添加一个这样的:
public ApplicationDbContext() : base("your connection string") {}