title: Entity Framework migration from existing production database with empty MigrationHistory table
body: <p>I have a downloaded production database with an empty MigrationHistory table (contents were accidentally deleted).</p>
  
  <p>I have an updated code model in my development environment (with no previous migrations).</p>
  
  <p>In other words, there's a mismatch between the downloaded production DB schema and the dev environment code model -- and no history between them.</p>
  
  <p>How do I scaffold a code-first migration (or get the SQL) to update the production database to the new model?</p>
  
  <p>I have tried the following, as per the suggestions <a href="http://msdn.microsoft.com/en-us/data/dn579398.aspx" rel="nofollow">here</a>:</p>
  
  <ol>
  <li>Enabling migrations in my project (<code>Enable-Migrations</code>)</li>
  <li>Adding an empty migration (<code>Add-Migration InitialCreate -IgnoreChanges</code>)</li>
  <li>Applying this migration (<code>Update-Database</code>)</li>
  </ol>
  
  <p>This results in a row being added to the MigrationHistory table.</p>
  
  <p>However, EF seems to think that this means that the current code model matches the database schema (which, of course, it doesn't).</p>
  
  <p>If I try adding a new migration (<code>Add-Migration UpdatedModel</code>), this migration comes out empty, which it shouldn't since the code model and the database do not match.</p>
  
  <p>How can I get a code-first migration (or the SQL) that reflects the changes between the code model and the database schema? (If I try doing <code>Add-Migration InitialCreate</code> without the <code>-IgnoreChanges</code> flag I get the whole database created from scratch, correctly reflecting the code model, but I want the changes.)</p>