I have a migration that create a column in a table.
public partial class AddName : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Name",
table: "MyTable",
nullable: false,
defaultValue: "Value 1");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name",
table: "MyTable");
}
}
I update my database with it. And I generate a new migration.
This last should be empty but it contains an useless AlterColumn.
public partial class Test : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "MyTable",
nullable: false,
defaultValue: "Value 1",
oldClrType: typeof(string),
oldType: "nvarchar(max)");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Name",
table: "MyTable",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldDefaultValue: "Value 1");
}
}
To generate this migrations and update database, I use dotnet-ef cli.
I check it and I find no difference between two migrations. When I update database with Test migration, no changes are applied to table.
I also test to update my database to a migration prior to AddName and create it again. But I have same result. Second migration stay fill with AlterColumn.
Someone already has this strange behavior?