Check pending migrations in Entity Framework?

In Entity Framework 6, I use the Update-Database command to apply migration. I have three environments that I juggle (DEV, QA and PROD) and update them with

Update-Database -ConnectionStringName DEV 

But now I would like to know which migration my PROD environment is in, and which migrations will be applied if I call Update-Database.

Is there a command to check which migration is applied last, and which will be applied if I run Update-Database?

+6
source share
1 answer

To find out which migrations were applied to the database, use the Get-Migrations command:

 Get-Migrations -ConnectionStringName PROD 

You can also check the contents of the __MigrationsHistory table in the right database. It contains information about all migrations applied to the database.

The following migration used depends on the existing migration files in your project. The migration file name includes a prefix, which is a timestamp that defines the time at which the migration file was generated (if you did not use the -force , which can result in reuse of an existing migration file that retains the existing timestamp string). Migrations apply according to this timestamp. Thus, the alphabetical order of your migration files indicates the order in which they are applied.

A safe way to check which migration will be applied next is to run Update-Database with the -Script , which generates an SQL script for the migration, but does not run it. Thus, you can see what migration will be applied if you run the real Update-Database .

+10
source

Source: https://habr.com/ru/post/1013858/


All Articles