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