Custom written migration does not run

c# entity-framework-core

Question

I want to write my own migration script. My migration class:

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);
        }
    }
}

But when I run Update-Database, nothing happens...

1
0
8/18/2018 8:44:46 PM

Accepted Answer

You need to specify the DbContext which the migration belongs to and the identifier of your migration by applying attributes to your migration class as shown below:

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


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow