Reputation: 4727
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?
Upvotes: 1
Views: 938
Reputation: 20117
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.
Upvotes: 1