3

I am using visual studio, EF Core I have for example Migration files

for example 20210314142045_RemoveCitizenShip3.cs as using Microsoft.EntityFrameworkCore.Migrations;

namespace CertificateSystem.DB.DB.Migrations
{
    public partial class RemoveCitizenShip3 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "CitizenShip",
                schema: "CertificateSystem",
                table: "CommercialEntity");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "CitizenShip",
                schema: "CertificateSystem",
                table: "CommercialEntity",
                nullable: true);
        }
    }
}

I want to take my project and publish it to production I understand that Migrations Is not a good way to work with on a production I think the best way to update my database it is to make a Migration on the developing version and create a SQL out of it and execute the SQL on the production

My problem is how do I create a SQL file from a Migration file?

I have read that https://stackoverflow.com/questions/49552550/get-sql-file-for-specific-migration-in-entity-framework-6-c-sharp

And I saw that Script-Migration -From X -to Y do some work but If I want to do it on specific file? How can I do it?

2
  • What do you mean by specific file? Do you mean from the first migration to that file(-to RemoveCitizenShip3), or from that file to the latest migration(-from RemoveCitizenShip3)? Commented Apr 6, 2021 at 10:37
  • I mean from last state of the database to the next migration Commented Apr 6, 2021 at 10:40

1 Answer 1

7

You can do

Script-Migration -From <PreviousMigration> -To <LastMigration>

In your case,

Script-Migration 20180904195021_InitialCreate

The above example creates a script for all migrations after the InitialCreate migration, using the migration ID. See the documentation And if you're using .net core CLI tools,

dotnet ef migrations script 20180904195021_InitialCreate

Always follow the documentation

Sign up to request clarification or add additional context in comments.

1 Comment

Sometimes its create to me a empty script do you know why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.