[英]How can I Update-Database?
this is the code used to generate the migration这是用于生成迁移的代码
dotnet ef migrations add InitialCreate --context DataContext --output-dir Migrations/SqlServerMigrations
and this is the DataContext.cs dotnet ef migrations add InitialCreate --context DataContext --output-dir Migrations/SqlServerMigrations
,这是 DataContext.cs
namespace WebApi.Helpers
{
public class DataContext : DbContext
{
protected readonly IConfiguration Configuration;
public DataContext(IConfiguration configuration)
{
Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// connect to sql server database
options.UseSqlServer(Configuration.GetConnectionString("WebApiDatabase"));
}
public DbSet<User> Users { get; set; }
}
}
but when I run Upadate-Database
I get the error "More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands."但是当我运行Upadate-Database
我收到错误消息“找到了多个 DbContext。指定使用哪个。对 PowerShell 命令使用‘-Context’参数,对 dotnet 命令使用‘--context’参数。”
How can I update the database using this migration?如何使用此迁移更新数据库?
Update-Database --context DataContext
As a part of the ef migrations add
, you specify your context as DataContext
.作为ef migrations add
的一部分,您将上下文指定为DataContext
。 I believe the above command should allow you to update the database accordingly.我相信上面的命令应该允许您相应地更新数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.