concept Migrate in category entity framework

appears as: Migrate
Entity Framework Core in Action, SE

This is an excerpt from Manning's book Entity Framework Core in Action, SE.

If you want to run your seed database method only when a new migration has been applied, you can use the DbContext method Database.GetPendingMigrations to get the list of migrations that are about to be applied. If this returns an empty collection, then there is no pending migration on the current database. You must call GetPendingMigrations before you execute the Database.Migrate method, because the pending migrations collection is empty after the Migrate method has finished.

Entity Framework Core in Action

This is an excerpt from Manning's book Entity Framework Core in Action.

If you’re running this example application downloaded from the Git repo that goes with this book, you don’t need to use the Migrate commands that follow. The code uses the context.Database.EnsureCreated command to create the database. This is less flexible than Migrate, but it doesn’t require you to type any commands.

This chapter covers the three ways of changing the structure of a database. The structure of the database is called the database schema—the tables, columns, constraints, and so on that make up a database. Creating and updating a database schema can seem simple because EF Core provides a method called Migrate to do it all for you; you create your entity classes and add a bit of configuration, and EF Core builds you a nice, shiny database.

The problem is that EF Core’s Migrate method hides a whole series of database migration issues that might not be immediately apparent; for example, moving data from one entity class to another entity class can cause loss of data when applying a database schema change. Getting a database change wrong on a database that has live data in it is a scary problem.