0
votes

I want to update database on Azure SQL to fit .Net Core application using Entity Framework Core migrations. The following command is advised online:

Update-Database -ConnectionString $ConnectionString -ConnectionProviderName "System.Data.SqlClient"

However, it does not work since Update-Database cmdlet does not recognize parameter –ConnectionString. How can automate database migrations?

1
I think parameter should by -Connection not -ConnectionStringvivek nuna
Supported parameters: Update-Database [[-Migration] <String>] [-Context <String>] [-Project <String>] [-StartupProject <String>] [<CommonParameters>]user2341923
didn't get you. You need to use Update-Database -Connectionvivek nuna
Update-Database : A parameter cannot be found that matches parameter name 'Connection'.user2341923
The question is: how can I tell to Update-Database which of the remote databases on Azure SQL is needed to be updated?user2341923

1 Answers

1
votes

How can automate database migrations?

EF does not support Automatic migrations, you may need to manually execute Add-Migration or dotnet ef migrations add for adding migration files. You could explicitly execute the command to apply the migrations, also you could apply migrations in your code.

If you want to apply migration at runtime, you could add the following code int the Configure method of Startup.cs

using (var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
    {
        scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
    }

For more details, you could refer to this thread.