我有一个在表中创建一列的迁移。
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");
}
}
我用它更新我的数据库。我生成了一个新的迁移。
最后一个应该是空的,但它包含一个无用的 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");
}
}
要生成此迁移并更新数据库,我使用了 dotnet-ef
cli。
我检查了一下,发现两次迁移之间没有区别。当我使用 Test
迁移更新数据库时,没有对表应用任何更改。
我还测试将我的数据库更新到 AddName
之前的迁移并再次创建它。但我有同样的结果。第二次迁移保持填充 AlterColumn
。
有人已经有这种奇怪的行为了吗?