title: EF Code first migrations not running after deploy to Azure
body: <p>I have two folders for my migrations (AuthContext and UserProfileContext), each has their own migration and some custom sql to run afterwards for data migrations and whatnot.</p>
  
  <p>This works fine when using package manager console. I</p>
  
  <ol>
  <li>Restore from production</li>
  <li>Run Update-Database -ConfigurationTypeName Migrations.Auth.Configuration</li>
  <li>Run Update-Database -ConfigurationTypeName Migrations.UserProfile.Configuration</li>
  </ol>
  
  <p>Then everything is very happy in the new database, migrations executed data shuffled where it needs to.</p>
  
  <p>I tried to test out the migrations on publish piece by:</p>
  
  <ol>
  <li>Restore production on dev database</li>
  <li>Single connection string (all contexts use the same) pointed to dev database</li>
  <li>Publish to azure web site</li>
  <li>Checked the box for Apply Code First Migrations</li>
  <li>Selected that single connection string</li>
  </ol>
  
  <p>Okay it published fine; however, when I went to look at the database, nothing happened! It did not create the necessary tables, columns, or data moves.</p>
  
  <blockquote>
    <p>TLDR; Code first migrations are not running after publish to Azure</p>
  </blockquote>
  
  <p><strong>Update 1</strong>
  I've tried any combination of the below: only one single connection string so I'm guessing that's not the issue, and execute migrations is checked.
  <img src="https://i.stack.imgur.com/pn0uq.png" alt="enter image description here"></p>
  
  <p>On publish the api runs but no database changes are made. I thought perhaps I needed to hit it first but I just get random errors when I try to use the api (which now of course relies on the new database setup), and the database is still not changed.</p>
  
  <p>I've seen a couple references out there about needing to add something to my Startup class but I'm not sure how to proceed.</p>
  
  <p><strong>Update 2</strong>
  I solved one issue by added "Persist Security Info=True" to my connection string. Now it actually connects to the database and calls my API; however, no migrations are running.
  I attached debugger to Azure dev environment and stepped through... on my first database call it steps into the Configuration class for the Migration in question, then barfs and I can't track down the error.</p>
  
  <pre><code>public Configuration()
  {
      AutomaticMigrationsEnabled = false;
      MigrationsDirectory = @"Migrations\Auth";
      ContextKey = "AuthContext";
  }
  </code></pre>
  
  <p><strong>Update 3</strong></p>
  
  <p>Okay, dug down and the first time it hits the database we're erroring. Yes this makes sense since the model has changed, but I have migrations in place, enabled, and checked! Again, it works fine when running "Update-Database" from package manager console, but not when using Execute Code First Migrations during publish to Azure</p>
  
  <blockquote>
    <p>The model backing the 'AuthContext' context has changed since the
    database was created. Consider using Code First Migrations to update
    the database (<a href="http://go.microsoft.com/fwlink/?LinkId=238269" rel="noreferrer">http://go.microsoft.com/fwlink/?LinkId=238269</a>).</p>
  </blockquote>
  
  <p><strong>Update 4</strong>
  Okay I found the root issue here. VS is setting up the additional web.config attrib for databaseInitializer on only one of my database contexts, the one not mentioned is in fact hit first from my app.</p>
  
  <p>So now I have to figure out how to get it to include multiple contexts, or, combine all of my stuff into a single context.</p>