How to apply an EF migration to a database hosted in Azure? azure entity-framework-core visual-studio


I'm creating an ASP.NET Core API, and I have one project in my solution named MyProj.API and another project named MyProj.Data. Both of them are Core Web app projects. Simply, API project includes all the controllers and other logic, whereas the Data project includes the models, context, repository and migrations. I have successfully hosted the app to Azure, but the point is that when publishing the API project, there was no option to choose the migration to apply. Though, if I run the dotnet ef dbcontext list --json command inside the API project, it successfully shows to me the context that comes from the Data project. Hence, I would like to learn whether there is a way to apply a migration manually to an app hosted in Azure?

8/8/2018 10:04:45 PM

Accepted Answer

You can applying migrations at runtime, or use Update-Database with -ConnectionString parameter in Visual Studio Package Management prompt.

For help, type Get-Help Update-Database -detailed in the prompt.

1/16/2020 3:00:08 PM

Popular Answer

For migration manually to .net core, you can follow this link .

You may need to manually run update-database under Package Manager Console of VS, or you could use Powershell, and cd to your project directory, and execute dotnet ef database update to apply any pending migrations for your context to the database, then deploy your application to azure web app.

Detailed steps as below: In your visual studio -> Package Manager Console, run the following command:

1. dotnet ef migrations add AddProperty
2. dotnet ef database update

Then re-publish the project.

Moreover, you could also follow this similar issue.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow