1

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?

5
  • I think parameter should by -Connection not -ConnectionString Commented Jun 19, 2018 at 6:57
  • Supported parameters: Update-Database [[-Migration] <String>] [-Context <String>] [-Project <String>] [-StartupProject <String>] [<CommonParameters>] Commented Jun 19, 2018 at 7:23
  • didn't get you. You need to use Update-Database -Connection Commented Jun 19, 2018 at 7:26
  • Update-Database : A parameter cannot be found that matches parameter name 'Connection'. Commented Jun 19, 2018 at 7:30
  • The question is: how can I tell to Update-Database which of the remote databases on Azure SQL is needed to be updated? Commented Jun 19, 2018 at 8:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.