Vadim Bondaruk
Vadim Bondaruk

Reputation: 173

EF Core database migrations

I know that in ef core you can generate migration script from one to next migrations. Lets say i have 5 migrations:

  1. Migration1
  2. Migration2
  3. Migration3
  4. Migration4
  5. Migration5

Migration3 and Migration4 already applied to database, and i want to generate script for Migrations 1, 2 and 5. Is it possible by using ef core tools? Or maybe there is some other tools?

Upvotes: 2

Views: 651

Answers (2)

komluk
komluk

Reputation: 599

If I correctly understood your problem you want to deploy migrations to a database? You can use .Net Core CLI for that:

dotnet ef migrations script

This will generate a SQL script from this migration to the latest migration

dotnet ef migrations script xxx_name

You can also generate a SQL script from migration to the specified migration.

dotnet ef migrations script from_migration to_migration

Upvotes: 2

pquest
pquest

Reputation: 3290

Each migration builds on the previous and is generated assuming everything that came before it is already there. It would be very dangerous to apply the migrations out of order, or use something other than EF core to modify the portion of your database you are using it to manage. That being said, you can use the dotnet ef migrations script command to generate a script moving from one migration to another. It will include all the migrations between them as well:

dotnet ef migrations script <FromMigration> <ToMigration> -o "FileName"

Upvotes: 0

Related Questions