简体   繁体   中英

Get SQL file for specific migration in Entity Framework Core C#

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM