ASP-MVC Code-first migrations checkbox not active

198 views Asked by At

I'm using VS Community 2013. I'm trying to web deploy an ASP-MVC app. I can deploy the app, but it can't create the database. When I set up the web deploy, the box for "Execute code first migrations (runs at application start)" checkbox is grey under my context. It is active for the "ApplicationDbContext (DefaultConnection).

I tried enable-migrations in the package manager console. I got some informative messages that helped me with the correct switches. My command was

Enable-Migrations -ContextTypeName Gators3.Models.ApplicationDbContext -enableautomaticmigrations

I also noticed that the changes to my Web.config talked about here are not being made. In fact, I don't even have a <contexts> section.

I've tried some of the tricks in other SO threads such as

"Execute Code First Migrations" checkbox disappeared from my publish profile

Execute Code first Migration

Visual Studio 2012, Publish (Web Deploy) - Code First Migrations not changing web.config

But nothing has helped.

1

There are 1 answers

0
Andy V On

This happened to me to. I tried deleting things, and re-enabling migrations, and rebooting, and restarting Visual Studio and ...

I gave up. I now have the following in my Web.Dev.config (for deploying to my dev server):

 <entityFramework>
    <contexts xdt:Transform="Insert">
        <context type="LDS.Models.ApplicationDbContext, LDSAssembly">
            <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[ 
 [LDS.Models.ApplicationDbContext, LDSAssembly], 
 [LDS.Migrations.MigrationConfiguration, LDSAssembly]
], EntityFramework" />
        </context>
    </contexts>
</entityFramework>

I can't tell the different in terms of behavior. I deploy new code with new migrations and the schema is up-to-date when my code executes. I probably pay a performance penalty to ensure the db is at the right version, but I'm too far in bed with Entity to change for this project.