EF Core Tip 1: Running your migrations when publishing

I was looking for a way to automatically update the database after a deploy. The only way I found so far to do this, is to do this in code in your Startup class.

In the Configure method, use this code to upgrade your database other than Development:

if(!env.IsDevelopment())
{
    db.Database.Migrate();
}

If you make sure to set the correct environment variable in the environment you’re deploying to, it will upgrade the database with your migrations.