0

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?

4

1 回答 1

1
Update-Database --context DataContext

作为 的一部分ef migrations add,您将上下文指定为DataContext。我相信上面的命令应该允许您相应地更新数据库。

于 2021-10-13T23:49:57.663 回答