Automatically Apply EF Core Database Migrations in Azure Function App on Startup

To apply database migrations to an Azure Function app on startup, you’ll need to have the following set up first:

Once the above is set up, you can set up the application to apply all migrations on startup, making for a link between the running application and the database it is dependent on. This is especially useful for local development – as you won’t run into cases where a local schema is outdated.

Add the following code to the Startup.cs file: