Entity Framework Core による DDL の生成(Script-Migration)

Tech Knowledge
公開: 2023-07-28

手順

Script-Migration From [To] [-Context コンテキスト名]
  • From(必須): From より後(From <)の DDL が生成される
  • To: To まで(≦ To)の DDL が生成される
  • -Context コンテキスト名: 複数の DbContext を併用してる場合、指定が必要

以下のような Migration の履歴がある場合

20230516073612_Hoge_A.cs ・・・(A)
20230705015302_Hoge_B.cs ・・・(B)
20230705023114_Hoge_C.cs ・・・(C)
20230705075249_Hoge_D.cs ・・・(D)

(A) より後の DDL((B)、(C)、(D))を生成したい場合

Script-Migration 20230516073612_Hoge_A
または
Script-Migration Hoge_A

自動生成で付与されたファイル名の年月日時分秒は省略できる。

(B)、(C) の DDL を生成したい場合

Script-Migration Hoge_A Hoge_C

(D) の DDL を生成したい場合

Script-Migration Hoge_C

参考

Script-Migration