我首先正在开发 .net core 3 项目代码。在此步骤中,我在表中添加了 2 列。然后我通过此代码 (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 次迁移。这是我关于迁移的第一个问题。