无法使用Ef Core删除数据库迁移

问题描述 投票:0回答:1

嗯,我正在尝试还原一个简单地添加一列的数据库迁移,请参阅:

 public partial class CreateColumnTypeCamera : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "type",
                table: "CAMERA",
                type: "varchar",
                nullable: false,
                defaultValue: "");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "type",
                table: "CAMERA");
        }
    }

执行dotnet ef database update之后,一切正常,并且我的数据库已更新。但是我想还原它,所以我尝试了dotnet ef database update CreateColumnTypeCamera

[ronaldo@localhost WebApi]$ dotnet ef database update CreateColumnTypeCamera
Done.

您可以看到我得到了“完成”,但是什么也没有恢复,该列没有被删除。如果我尝试删除迁移,则会出现错误:

[ronaldo@localhost WebApi]$ dotnet ef migrations remove
The migration '20200329134024_CreateColumnTypeCamera' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.

编辑1:

我将“ update”命令应用于“ LastGoodMigration”,而不是我的错误迁移,并且一切正常。但是删除操作中的错误仍在继续,因此我注意到这是由于以下原因:

 if (Database.ProviderName != "Microsoft.EntityFrameworkCore.InMemory")
      {
        Database.Migrate();
      }

有什么办法可以解决?如果我尝试在此行中应用“ ef remove”,则会收到上面显示的错误。

entity-framework .net-core ef-migrations
1个回答
0
投票

转到数据库,表EF_migrations并删除具有特定ID的迁移(表行),然后可以从迁移文件夹中删除文件。不要忘记手动更新受此迁移影响的表。

© www.soinside.com 2019 - 2024. All rights reserved.