[英]How can I Update-Database?
这是用于生成迁移的代码
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; }
}
}
但是当我运行Upadate-Database
我收到错误消息“找到了多个 DbContext。指定使用哪个。对 PowerShell 命令使用‘-Context’参数,对 dotnet 命令使用‘--context’参数。”
如何使用此迁移更新数据库?
Update-Database --context DataContext
作为ef migrations add
的一部分,您将上下文指定为DataContext
。 我相信上面的命令应该允许您相应地更新数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.