简体   繁体   English

获取 SQL 文件,用于 Entity Framework Core C# 中的特定迁移

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

I am using visual studio, EF Core I have for example Migration files我正在使用 Visual Studio,EF Core 我有例如迁移文件

for example 20210314142045_RemoveCitizenShip3.cs as using Microsoft.EntityFrameworkCore.Migrations;例如20210314142045_RemoveCitizenShip3.cs使用 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我想将我的项目发布到生产中 我知道迁移不是在生产中使用的好方法 我认为更新我的数据库的最佳方法是在开发版本上进行迁移并创建 SQL它并在生产上执行 SQL

My problem is how do I create a SQL file from a Migration file?我的问题是如何从迁移文件创建 SQL 文件?

I have read that https://stackoverflow.com/questions/49552550/get-sql-file-for-specific-migration-in-entity-framework-6-c-sharp我读过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?我看到 Script-Migration -From X -to Y 做了一些工作,但是如果我想在特定文件上做呢? 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.上面的示例使用迁移 ID 在 InitialCreate 迁移之后为所有迁移创建脚本。 See the documentation And if you're using .net core CLI tools,请参阅文档如果您使用的是 .net 核心 CLI 工具,

dotnet ef migrations script 20180904195021_InitialCreate

Always follow the documentation始终遵循文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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