Search code examples
entity-frameworkazureef-code-firstentity-framework-migrations

Deploying to Azure not running EF Code First Migrations


I am running Entity Framework with Code First Migrations. My new release adds a table, modifies a few tables, and run some scripts. This works perfectly when developing locally using update-database.

Upon deployment the new table was not created and I was receiving errors from my client. I attached the debugger to the deployed site to track through what was happening. It reached the controller, went through the normal flow, and upon hitting the first database call to the new (but not actually existing yet) table it hopped into the Configuration class for my migration.

internal sealed class Configuration : DbMigrationsConfiguration<myProject.api.AuthContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        MigrationsDirectory = @"Migrations\Auth";
        ContextKey = "myProject.api.AuthContext";
    }

So I'm thinking great, all should be well. It goes through all of these, returns to the initial database call, but then that call returns an error, pasted below

The model backing the 'AuthContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

This is surprising since indeed I have enabled code first migrations! Using the standard enable-migrations and add-migration, which work perfectly on my local machine when I issue the update-database command.

1) How can I get my Code First migrations to run once deployed to Azure?

Update 1

Here are my publish settings. For some reason I do not have the checkbox option for: "Execute Code First Migrations" and am guessing that's the issue... enter image description here


Solution

  • Huzzah! My update was the issue. I found from other SO posts that his happens sometimes. A Clean and Rebuild, followed by restarting VS, restored the 'Execute Code First Migrations' checkbox. Re-deployed and everything worked perfectly.