![](/img/trans.png)
[英]EF Core migration with SQLite database: unable to create object of type
[英]Migration with dotnet ef error: Unable to create an object of type 'MyClass'
我正在嘗試使用 dotnet ef migrations add MyMigration 進行遷移,但 shell 返回錯誤:無法創建“AuthDbContext”類型的對象。 有關設計時支持的不同模式,請參閱https://go.microsoft.com/fwlink/?linkid=851728 。
這是我的 AuthDbContext.cs 文件:
using Auth.Data.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Auth.Data
{
public class AuthDbContext : IdentityDbContext<User>
{
private readonly string connStr;
//public DbSet<User> Users { get; set; }
public AuthDbContext(DbContextOptions<AuthDbContext> options) : base(options) //string connStr)
{
//this.connStr = connStr;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// string connStr = "";
// connStr = "";
// if (!optionsBuilder.IsConfigured)
// {
// optionsBuilder
// .EnableSensitiveDataLogging(true)
// .UseSqlServer(connStr);
// }
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("auth");
//modelBuilder.Entity<User>().HasKey(p => new { p.User_id });
base.OnModelCreating(modelBuilder);
}
}
}
有人可以幫我理解嗎? 謝謝。
你忘了添加這一行
base.OnConfiguring(optionsBuilder);
EF Core 無法完成上下文實例化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.