title: Unable to generate explicit migration (EF5) (migrations pending)
body: <p>We are using Code-first migrations with EF5 on (localdb)\v11.0 (Vstudio 2012) and everything has worked nicely so far.</p>
  
  <p>However - today I needed to create a couple of indexes on a few of tables and ran into problems.</p>
  
  <p>First I did this in PM:</p>
  
  <pre><code>PM&gt; add-migration AddIdxToOutage
  Scaffolding migration 'AddIdxToOutage'.
  </code></pre>
  
  <p>I modified the code in the scaffolded migration to:</p>
  
  <pre><code>public override void Up()
          {
              Sql(@"CREATE NONCLUSTERED INDEX [idx_WtgId_StartDateTime_EndDateTime] ON [dbo].[Outages]
  (
      [WtgId] ASC,
      [StartDateTime] ASC,
      [EndDateTime] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]");
          }
  </code></pre>
  
  <p>I updated the database and the result was this:</p>
  
  <pre><code>PM&gt; update-database -startupprojectname D3A.Data -force -verbose
  Using StartUp project 'D3A.Data'.
  Using NuGet project 'D3A.Data'.
  Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
  Target database is: 'D3A.Data.StorageContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
  Applying code-based migrations: [201310301258520_AddIdxToOutage].
  Applying code-based migration: 201310301258520_AddIdxToOutage.
  CREATE NONCLUSTERED INDEX [idx_WtgId_StartDateTime_EndDateTime] ON [dbo].[Outages]
  (
      [WtgId] ASC,
      [StartDateTime] ASC,
      [EndDateTime] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  [Inserting migration history record]
  Running Seed method.
  </code></pre>
  
  <p>The idx was created on the table and everybody was happy.</p>
  
  <p>However - when I created the next index, I ran into problems. I created an empty migration task as</p>
  
  <pre><code>PM&gt; add-migration AddIdxToState
  Unable to generate an explicit migration because the following explicit migrations are pending: [201310301258520_AddIdxToOutage]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
  </code></pre>
  
  <p>Pardon my French - but WT*?</p>
  
  <p>There seems to be no way around this. I can revert to the migration step preceding addition of the first idx, add the idx'es again and the same thing happens again.</p>
  
  <p>Can you tell me what I am missing here? What am I doing wrong?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I initially thought that my trouble was executing raw SQL against the database/localdb, but it seems like everything I do now stops after the first add-migration.</p>
  
  <p>I just added a new table to the database and this is the std-out result from PM Console:</p>
  
  <pre><code>PM&gt; add-migration AddMyLoggerTable
  Scaffolding migration 'AddMyLoggerTable'.
  The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration 201310301419063_AddMyLoggerTable' again.
  PM&gt; update-database -startupproject DongEnergy.D3A.Data -verbose
  Using StartUp project 'D3A.Data'.
  Using NuGet project 'D3A.Data'.
  Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
  Target database is: 'D3A.Data.StorageContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
  Applying code-based migrations: [201310301419063_AddMyLoggerTable].
  Applying code-based migration: 201310301419063_AddMyLoggerTable.
  CREATE TABLE [dbo].[MyLoggerTable] (
      [id] [int] NOT NULL,
      [functionId] [int],
      [elapsedTime] [bigint],
      [noOfRecords] [int],
      [dateCreated] [datetime] DEFAULT getDate()
  )
  [Inserting migration history record]
  Running Seed method.
  PM&gt; add-migration AddMyLoggerTableFunction
  Unable to generate an explicit migration because the following explicit migrations are pending: [201310301419063_AddMyLoggerTable]. Apply the pending explicit migrations before attempting to generate a new explicit migration.
  </code></pre>
  
  <p>Notice how I add a new, empty migration task, use the CreateTable-method and have that successfully updated in the database. But when I add a new migration step, it complains that the task that was just "committed" to the database is still "pending" - even though both migrationhistory and database objects have been updated.</p>