title: Entity Framework code-first: migration fails with update-database, forces unneccessary(?) add-migration
body: <p>I have a funny effect using migration (EF 5.0) and code-first:</p>
  
  <p>I created some models with GUID primary keys. (BTW: It is important for me, that SQL Server uses <code>NEWSEQUENTIALID()</code>, which seems to be the default value in the current version)</p>
  
  <p>At some point I activated migrations. I added some code to the initial migration, this is mostly <code>.Index()</code> as needed.</p>
  
  <p>When I delete the database and call update-database, I get the following error:</p>
  
  <blockquote>
    <p>Unable to update database to match the current model because there
    are pending changes and automatic migration is disabled. Either write
    the pending model changes to a code-based migration or enable
    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.</p>
  </blockquote>
  
  <p>I tried <code>AutomaticMigrationsEnabled = true</code>, which worked without changing or adding anything!</p>
  
  <p>But since I don't want <code>AutomaticMigrationsEnabled</code>, I also tried deleting the database again, called <code>update-database</code> and then <code>add-migration</code>. I ended up with an additional migration that seems not to change anything (see below). I also tried adding these lines to the bottom of the initial migration - but this does not change anything.</p>
  
  <p>One of the models:</p>
  
  <pre><code>[Table(Speaker.TABLENAME)]
  public class Speaker : BaseModel
  {
      public const String TABLENAME = "Speaker";
  
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public Guid Id { get; set; }
  
      [Required]
      [MaxLength(50, ErrorMessage = "Name must be 50 characters or less")]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>The initial migration code:</p>
  
  <pre><code>public partial class InitialCreate : DbMigration
  {
      public override void Up()
      {
          // [...]
          CreateTable(
              "dbo.Speaker",
              c =&gt; new
                  {
                      Id = c.Guid(nullable: false, identity: true),
                      Name = c.String(nullable: false, maxLength: 50),
                  })
              .PrimaryKey(t =&gt; t.Id)
              .Index(t =&gt; t.Name, true, false);   // added manually: unique Name
          // [...]
      }
  }
  
  internal sealed class Configuration : DbMigrationsConfiguration&lt;MyProject.Repositories.DBContext&gt;
  {
      public Configuration()
      {
          AutomaticMigrationsEnabled = false;
      }
  
      protected override void Seed(MyProject.Repositories.DBContext context)
      {
          // ...
      }
  }
  </code></pre>
  
  <p>Below is the code created by add-migration: It does not seem to do anything new - maybe I am missing something?</p>
  
  <pre><code>public partial class UnneccessaryMigration : DbMigration
  {
      public override void Up()
      {
          // isn't this the exact same code from InitialMigrations?
          AlterColumn("dbo.Speaker", "Id", c =&gt; c.Guid(nullable: false, identity: true));
          // ...
      }
  
      public override void Down()
      {
          //...
          AlterColumn("dbo.Speaker", "Id", c =&gt; c.Guid(nullable: false));
      }
  }
  </code></pre>
  
  <p>So I am curious: What did I do to disorientate migrations? And what can I do to get it working with just one initial migration?</p>
  
  <p><strong>Solution</strong>: The following workaround did it for me:</p>
  
  <ol>
  <li>I deleted the database and all migrations as decribed here:
  <a href="https://stackoverflow.com/a/11679386/3168401">https://stackoverflow.com/a/11679386/3168401</a></li>
  <li>Executed Enable-Migrations + Add-Migration Initial</li>
  <li>Merged my handmade .Index() changes into the file.
  Now Update-Database works again - also repeatedly, when deleting the database.</li>
  </ol>