Deploying your data layer
When your database layer is deployed in production or in staging, usually, an empty database already exists, so you must apply all the migrations in order to create all the database objects. This can be done by calling context.Database.Migrate()
. The Migrate
method applies the migrations that haven’t been applied to the databases yet, so it may be called safely several times during the application’s lifetime.
context
is an instance of our DbContext
class that must be passed through a connection string with enough privileges to create tables and to perform all the operations included in our migrations. Thus, typically, this connection string is different from the string we will use during normal application operations.
During the deployment of a web application on Azure, we are given the opportunity to check migrations with a connection string we provide. We can also check migrations manually by calling the context.Database.Migrate(...