Entity Framework 5 Automatic Code Migration

In my current web project, I am trying to configure code migration. I installed my db initializer as follows in my MVC4 project

protected void Application_Start() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyContext, Configuration>()); } 

I can make changes to my first code models, and this updates the database to the last automatic migration, as expected when starting the website.

However, I am trying to add explicit migration through the Add-Migration FirstMigration console to add some indexes. This adds the code file 201301071708126_FirstMigration to my project, and I can add it to my index code quite easily here.

But it will not start automatically when you restart the website. I need to run Update-Database from the console in order to apply this migration.

I followed this msdn tutorial , but I don’t see what I am doing wrong, as it suggests me that explicit migration starts automatically.

In my configuration file, I have the following constructor

 public Configuration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; } 
+4
source share
2 answers

I found the answer to this a bit back, and I missed some information in the question.

I have 2 websites, an MVC application and a WEBAPI application. I need to have database initialization, otherwise it does not work properly.

+4
source

in my application constructor

Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MYContext>());

and he updates the model.

-1
source

All Articles