我正在开发一个基于.NET Core 3的项目,采用代码优先模式。在这一步骤中,我向我的表中添加了两个列。然后,我通过以下代码(CLI)对解决方案进行了迁移操作。
dotnet ef --startup-project ../MyApi.Api migrations add actorInfomart
我的迁移返回了这个结果:
public partial class actorInfomart : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsSeries",
schema: "film",
table: "Movie",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "ExtInfo",
schema: "act",
table: "Actor",
maxLength: 100,
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsSeries",
schema: "film",
table: "Movie");
migrationBuilder.DropColumn(
name: "ExtInfo",
schema: "act",
table: "Actor");
}
}
看起来是正确的。问题出在这里。当我尝试更新迁移时,就会出现以下错误:
There is already an object named 'Actor' in the database.
我的迁移正在尝试在我的数据库中创建新表。但是在迁移中没有为此做任何操作。以下是我的迁移更新CLI命令。
dotnet ef --startup-project ../MyApi.Api database update actorInfomart
在终端中(我正在使用Mac),输入以下命令:
info: Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20191231100058_Initial'.
Applying migration '20191231100058_Initial'.
我该如何应用最新的迁移?在第一个和最后一个之间有10个迁移。这是我在迁移方面遇到的第一个问题。
dotnet ef migrations add
命令时的实际数据库布局。 - Tseng