繁体   English   中英

相当于修改 EFCore 迁移

[英]Equivalent of Modifying EFCore a Migration

客观的

在更改Migration.cs文件中的某些内容后,我想要像 Modify-Migration 这样的东西。

已经尝试过

有些时候我不小心使用了Annotation但现在我想删除它
我试图从这里删除这一行: .Annotation("SqlServer:ValueGenerationStrategy",SqlServerValueGenerationStrategy.IdentityColumn),

migrationBuilder.CreateTable(
    name: "LateFine",
    columns: table => new
    {
        StudentId = table.Column<int>(nullable: false)
        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
        FineAmount = table.Column<int>(nullable: false)
    },
    constraints: table =>
    {
        table.PrimaryKey("PK_LateFine", x => x.StudentId);
    });

并对数据库进行此更改,以便我的表的 SQL_Server 设计如下所示:

Identity Specification: No

我已经知道,使用DatabaseGenerated(DatabaseGeneratedOption.None)首先不会产生该注释。

这是以前的代码

class LateFine
{
    [Key]
    public int StudentId { get; set; }
    public int FineAmount { get; set; }
}

这是我目前的修改

class LateFine
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int StudentId { get; set; }
    public int FineAmount { get; set; }
}

构建解决方案后,使用Update-Database命令,我得到了这个: No migrations were applied. The database is already up to date. No migrations were applied. The database is already up to date.

如果您已经有多个迁移文件,只需回滚到上一次迁移,然后再次更新这个修改后的迁移文件。依次执行以下命令

1.Update-database -Migration YourLastMigrationName
2.Update-database -Migration YourAboveModifiedMigrationName

参考https://www.learnentityframeworkcore.com/migrations#reversing-a-migration

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM