“Execute Code First Migrations” checkbox disappeared from my publish profile

只愿长相守 提交于 2019-11-29 01:38:06
Pavlo Kyrylenko

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)"

Since asking this question, I've run into this problem several more times in multiple versions of MVC and EF (all code first though of cource). When it happens, don't save the changes to your publish profile, make sure you are on the 'debug' build configuration, clean solution and rebuild solution. And if all that fails, restart Visual Studio and try again. So far, this has always solved the problem for me.

This happened to me in VS2013. Neither cleaning the solution, nor restarting it worked. I tried to "re-enable" migrations and it worked. Even though I got an error message that migrations have already been enabled in project, the "Execute Code First Migrations" checkbox appeared again.

Since nothing mentioned above worked.
I downloaded the publish profile from azure and it worked flawlessly the first time

I had this problem and for me it had a different cause to any I've found documented elsewhere.

My application is spread over many projects in a solution. As I use interfaces and a separate View/Presentation model to wrap calls to the database, my front web project had no direct reference to the project containing the DbContext class. Note that this posed no problem to my running the site locally. I do this so that developers in the front end web project are not tempted to bypass the Presentation layer and go more directly to the database.

Adding this reference immediately fixed the problem and now I see the 'Execute Code First Migrations' checkbox in my Publish Profile dialog.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!