Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm using web deploy to deploy an MVC4 application using EF5 code first. I made a publish profile called "development" that uses web deploy for application and database using the 'Execute Code First Migrations' checkbox to run migrations on application startup. The publishing worked great for a while. At some point I added a new publish profile called "test" to deploy to another server, which uses the ftp method of deploy and no automatic migrations. This works fine too. However, when I tried to use my old "development" publish profile again, VS changes the settings automatically to the dbDacFx way ('Update database' checkbox instead of 'Execute Code First Migrations') and I can't get it back to the way it was. There were some other changes to the project while using the 'Test' profile, but nothing that seems to me like it could cause this. Does anyone know why VS thinks my project doesn't use code first anymore?

like image 877
EPLKleijntjens Avatar asked Oct 29 '13 16:10

EPLKleijntjens


People also ask

How do I enable migrations in Visual Studio?

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.


1 Answers

Here is the right answer - is solved the problem for me. Just rename your connection string exactly as your DbContext, e.g.

        public ApplicationDbContext()
        : base("Vocabulary.Domain.ApplicationDbContext", throwIfV1Schema: false)
    {
    }

Note that name should include namespace like "Vocabulary.Domain.ApplicationDbContext". Don't forget to update .pubxml files:

    <ObjectGroup Name="Vocabulary.Domain.ApplicationDbContext" Order="1" Enabled="True">

This article describes when publish dialog has or has no the tick "Execute Code First Migrations (runs on application start)"

like image 66
Pavlo Kyrylenko Avatar answered Sep 18 '22 12:09

Pavlo Kyrylenko