Execute Code First Migrations is Grayed Out in Publish Settings

前端 未结 2 1496
南旧
南旧 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<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.

    0 讨论(0)
  • 2020-12-18 08:31

    I believe you see the following "Execute Code First Migration" disabled when you try to publish your MVC application:

    enter image description here

    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

    0 讨论(0)
提交回复
热议问题