自定义书面迁移无法运行

时间:2018-08-18 20:10:37

标签: c# entity-framework-core

我想编写自己的迁移脚本。我的迁移课程:

using Microsoft.EntityFrameworkCore.Migrations;

namespace Foo.Migrations
{
    public class FooMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
          string script ="<some long script>"
            migrationBuilder.Sql(script);
        }
    }
}

但是当我运行Update-Database时,什么也没发生...

1 个答案:

答案 0 :(得分:0)

您需要通过将属性应用于迁移类来指定迁移所属的DbContext和迁移标识符,如下所示:

[DbContext(typeof(MyDbContext))]
[Migration("MyCustomMigration")]
public class FooMigration : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        string script = "<some long script>";
        migrationBuilder.Sql(script);
    }
}