Using Windows Azure and attempting to publish my MVC3 Application. The check box for Execute Code First Migration in the settings panel of the Publish web application is grayed out. What changes do I need to make to be able to enable it?
From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure Migrations.
Code First Migrations allow you to create a new database or to update existing database based on your model classes by using Package Manager Console exist within Visual Studio 2013 or Visual Studio 2012.
I believe you see the following "Execute Code First Migration" disabled when you try to publish your MVC application:
This is potentially because either you do not full code written for Code migration in your application as well no or incorrect DB setup in your web.config as described here.
In order to have Code Migration enabled, you must have a DB configured (in case of Windows Azure you need to provide SQL Database info in the web.config) in web.config and a complete class is written on how the code migration will happen depend on your model. Here is an example on how to achieve it.
http://msdn.microsoft.com/en-us/library/dd394698#efcfmigrations
I am assuming that you have Entity Framework model and in your database already (if not then you need to do some reading, answer by @AvkashChauhan would be indeed a good starting point).
However if you do have a model and all the configurations like:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new YourEntityMap());
}
and all the entity mappings like:
public class YourEntityMap : EntityTypeConfiguration<YourEntity>
{
public YourEntityMap()
{
this.HasKey(t => t.Id);
}
}
and you still don't get the darn checkbox enabled you might want to do following steps:
Go to Tools
> NuGet Package Manager
> Package Manager Console
Then in console write
Enable-Migrations -ContextTypeName Company.Models.YourDevContext
where Company.Models.YourDevContext
is your Database Context (look for class that inherits from DbContext
should be same one that has OnModelCreating
override).
after running command you should get something like:
At this point you should have Migrations
folder added to the solution more on how to handle migrations here
Hope this saves you some time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With