I'm building an application using ASP.NET MVC 4 with Entity Framework 5.0. I've recently learned about EF Code-First Migrations tool you can implement on your application for your database. I ran "Enable-Migration" in the PM Console, and it enabled successfully and created the "InitialCreate.cs" class as expected with the appropriate up() and down() methods filled in with the table creations.
Then I went ahead and added another class (Category.cs) with 2 simple properties (id, name) and wanted to add this migration to the database. I ran "Add-Migration AddCategoryClass" in my PM to get this message:
Scaffolding migration 'AddCategoryClass'.
The Designer Code for this migration file includes a snapshot of your current Code
First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration 201307301938256_AddCategoryClass' again.
It created the migration file in the Migrations folder, but when I open up the ".cs" file it created, the Up() and Down() methods are blank. I was expecting it to create a table and add the fields respectively. Out of curiousity, i ran "Update-Database" and it went through successfully (after changing AutomaticMigration = true in the Configuration.cs file). When I built my application, the table appeared in the database.
So my question is --> Why are the Up() and Down() methods blank?
For the record, the "Update-Database" command does not work if AutomaicMigrations = false in the Configuration.cs file; giving me the following error:
Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
I'm assuming these shouldn't be and it'd be helpful in the future to look at my migrations and see what I did. Any help or guidance would be great. Thank you in advanced.
I'm using VS 2012 on Win 7 64bit.