In my current web project I'm trying to set up code migrations. I set up my db initialiser as follows in my MVC4 project
protected void Application_Start()
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, Configuration>());
}
I can make changes to my code first models and this updates the database to the latest automatic migration as expected when I start up the website.
However I'm trying to add an explicit migration through the console Add-Migration FirstMigration
so I can add some indexes. This adds the code file 201301071708126_FirstMigration
to my project and I can add in my index code here easily enough.
But this won't run automatically when I restart the website. I have to run Update-Database
from the console to apply this migration.
I followed this tutorial on msdn but I can't see what I'm doing wrong as it suggests to me that the explicit migration should run automatically.
In my configuration file I have the following constructor
public Configuration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
}