在Entity Framework Core C#中获取用于特定迁移的SQL文件 [英] Get SQL file for specific migration in Entity Framework Core C#
问题描述
我正在使用Visual Studio EF Core例如,我有迁移文件
I am using visual studio, EF Core I have for example Migration files
例如 20210314142045_RemoveCitizenShip3.cs
作为使用Microsoft.EntityFrameworkCore.Migrations;
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);
}
}
}
我想把我的项目发布到产品中,我知道迁移不是处理产品的好方法我认为更新数据库的最佳方法是在开发版本上进行迁移,并从中创建SQL,然后在生产环境中执行SQL
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文件?
My problem is how do I create a SQL file from a Migration file?
我已阅读 https://stackoverflow.com/questions/49552550/get-sql-file-for-specific-migration-in-entity-framework-6-c-sharp
我看到从X到Y的Script-Migration做了一些工作,但是如果我想在特定文件上做呢?我该怎么办?
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?
推荐答案
您可以
Script-Migration -From <PreviousMigration> -To <LastMigration>
就您而言,
Script-Migration 20180904195021_InitialCreate
上面的示例使用迁移ID为InitialCreate迁移后的所有迁移创建脚本.请参见文档如果您使用的是.net核心CLI工具,
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
始终遵循文档
这篇关于在Entity Framework Core C#中获取用于特定迁移的SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!