title: How to manually (via code) apply DbMigration which was manually crafted?
body: <p>I manually created a class</p>
  <pre><code>  public class AddClientsTable : DbMigration, IMigrationMetadata
    {
          
      string IMigrationMetadata.Id
      {
        get { return &quot;201611281757258_AddClientsTable&quot;; }
      }
  
      string IMigrationMetadata.Source
      {
        get { return null; }
      }
  
      string IMigrationMetadata.Target
      {
        get { return &quot;AddClientsTable-Migration&quot;; }
      }
  
      public override void Up() {
        CreateTable(&quot;Clients&quot;, t =&gt; new {
            ClientId = t.Guid(name:&quot;ClientId&quot;),
            Name = t.String()
            })
        .PrimaryKey( t =&gt; t.ClientId, &quot;ClientId&quot;)
        .Index( t =&gt; t.ClientId, &quot;PK_Clients&quot;, true);
      }
  
      public override void Down() {
        DropIndex(&quot;Clients&quot;, &quot;PK_Clients&quot;);
        DropTable(&quot;Clients&quot;);
      }
  
    }
  </code></pre>
  <p>and i want to apply it via code-first migrations <em>from code</em> like this :</p>
  <pre><code>      var migration = new AddClientsTable();
        migration.Up();
        context.RunMigration(migration);
  </code></pre>
  <p>which I stole from <a href="https://stackoverflow.com/a/34767667/5767019">here</a> but when I run the code I'm getting this exception :</p>
  <pre><code>Unable to cast object of type 'System.Data.Entity.Migrations.Model.CreateIndexOperation' to type 'System.Data.Entity.Migrations.Model.HistoryOperation'.
  </code></pre>
  <p><code>HistoryOperation</code> is the operation which updates <code>__MigrationHistory</code> table ?  so How do I do that via code ?</p>
  <p>Am I missing something or the EntityFrameowrk <code>Update-Database</code> command does more than what I'm aware of ?</p>