Execute Code First Migrations is Grayed Out in Publish Settings

前端 未结 2 1505
南旧
南旧 2020-12-18 07:39

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 gra

2条回答
  •  误落风尘
    2020-12-18 08:28

    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
    {
        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.

提交回复
热议问题