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
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."
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
. I believe the above command should allow you to update the database accordingly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.