title: Entity Framework Code Migrations - Stuck on Initial Migration
body: <p>I have added EF 5 to my project via Nuget and enabled migrations with the "Enable-Migrations" command. I have then called "Add-Migration" to generate the base code for generating the schema.</p>
  
  <p>I then added a property to one of my domain objects (string property called "TestProperty") and added a mapping to my EntityTypeConfiguration file (we're ignoring the conventions at the moment). </p>
  
  <p>Calling "Add-Migration" again produces the error:</p>
  
  <pre><code>Unable to generate an explicit migration because the following explicit migrations are pending: [201303262144218_Initial]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
  </code></pre>
  
  <p>But calling "Update-Database" produces a sql exception because the tables already exist:</p>
  
  <pre><code>There is already an object named 'Customer' in the database
  </code></pre>
  
  <p>In my constructor for my DbContext I have tried the different update strategies, e.g.:</p>
  
  <pre><code>Database.SetInitializer&lt;UnitOfWork&gt;(new DropCreateDatabaseAlways&lt;UnitOfWork&gt;());
  </code></pre>
  
  <p>Am I missing something obvious?
  I tried the solution here but it didn't work: <a href="https://stackoverflow.com/questions/13238203/automatic-migrations-for-asp-net-simplemembershipprovider">Automatic Migrations for ASP.NET</a></p>
  
  <p>Thanks</p>
  
  <p>EDIT: Update
  The key to getting past the first step is to create the initial migration and then delete the generated code from the Up and Down methods (<a href="http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/" rel="noreferrer">http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/</a>). </p>
  
  <p>I can then update the model and the EF map and then run Add-Migration. This generates a migration with the correct Up and Down code.</p>
  
  <p>The problem is then trying to apply the update. Update-Database produces the error "Unable to update database to match the current model because there are pending changes and automatic migration is disabled...automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
  You can use the Add-Migration command to write the pending model changes to a code-based migration". Ok, so I try Add-Migration again and it produces another migration with the exact same code as the last one. </p>
  
  <p>I run Update-Database and get the same error again. I try "Update-Database -TargetMigration 201304080859556_MyMigration -Force" but this produces "The specified target migration '201304080859556_MyMigration' does not exist. Ensure that target migration refers to an existing migration id" - It does!</p>
  
  <p>Very frustrating!</p>