我正在创建一个有3个项目的解决方案,一个是EF核心,一个是数据库,最后一个是API。API是启动项目。我正在尝试从数据库项目构建一个迁移。此迁移应创建身份包的内置用户表。但是,我一直收到上面的错误。
我所有的项目都是ASP.NET Core5.0
我使用的包是:
对于DB项目:
*EntityFrameWorkCore
*EntityFrameWorkCore.Tools
*Install-Package Pomelo.EntityFrameworkCore.MySql -Version 5.0.0-alpha.2
*Microsoft.AspNetCore.Identity
*Microsoft.AspNetCore.Identity.EntityFrameworkCore
对于API项目:
*EntityFrameWorkCore.Design
我已经在API启动项目中引用了DB项目
在API项目中,我做了以下更改:
到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" });
});
}对于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"
}
}最后,我的DBAccessContect是:
public class DBAccessContext : IdentityDbContext<User>
{
public DBAccessContext (DbContextOptions<DBAccessContext> options) : base(options)
{
}
}用户所在位置
public class User : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}发布于 2021-03-08 19:33:37
通过将我的所有框架包从6.0.0预览版降级到5.0.3稳定版本,我解决了这个错误
https://stackoverflow.com/questions/66526701
复制相似问题