Automatic Migrationの方法
いつも忘れてしまうので、メモです。
パッケージマネージャーコンソールで下記を打つ
PM> Enable-Migrations -EnableAutomaticMigrations
コンテキスト型指定の場合
PM> Enable-Migrations -EnableAutomaticMigrations -ContextTypeName コンテキスト型</code>
Migrations/Configurations.csに追記
public Configuration()
{
AutomaticMigrationsEnabled = true; //Automatic Migration有効
AutomaticMigrationDataLossAllowed = true; //Migration時のデータ損失を許容
ContextKey = "WebApplication.Models.Context";
}
Global.aspxに追記
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Database.SetInitializer(new MigrateDatabaseToLatestVersion<コンテキストの型, 初期化の最中に使用する移行構成の型>()); //これ追加ー
}