簡體   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