How to run "dotnet ef migrations script" from the last migration

azure-devops entity-framework-core

Question

In Azure DevOps I have a build task with the following command:

dotnet ef migrations script --output path/migrations-script.sql --idempotent

In my release pipeline I run the generated script.

The issue I've got is that the above command runs from the first migration. I know I can specify a from argument for this command, but you have to specify the name of migration. Is there any way to generate the script from the last migration without specifying its name?

1
-1
1/20/2020 2:11:40 AM

Accepted Answer

Is there any way to generate the script from the last migration without specifying its name?

As I know, it's necessary for us to specify the name when we try to generate script from last migration, unless we have only one migration.

See the details about dotnet ef migrations script:

Arguments:

From: The starting migration. Migrations may be identified by name or by ID. The number 0 is a special case that means before the first migration. Defaults to 0.

To: The ending migration. Defaults to the last migration.

So if we have more than one migrations, we have to specify From with the start migration we want. This behavior is by design. Check this post, to generate script from last migration we should use format like:

dotnet ef migrations script -from (MigrationYouWant-1) -to MigrationYouWant

So I'm afraid there's no other way to do this in Devops pipeline or local machine, we have to specify the command with name. Hope my answer can help to clarify something for you:)

0
1/20/2020 3:21:25 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow