title: Entity Framework Code First Migration issue with linking tables
body: <p>I'm using EF 5.0 code first, using automatic migrations via the PM console.</p>
  
  <p>I'm attempting to apply a 4th migration to a project and the convention based naming of my linking tables is causing them to be dropped and recreated with a different name.  This has not occurred during any of the previous migrations.</p>
  
  <p>Example :</p>
  
  <p>I have 2 classes User and Site.</p>
  
  <p><strong>InitialCreate Migration</strong></p>
  
  <p>This created a link table called "UserSites" by convention.</p>
  
  <pre><code>CreateTable(
             "dbo.UserSites",
              c =&gt; new
                  {
                      User_Id = c.Guid(nullable: false),
                      Site_Id = c.Guid(nullable: false),
                  })
              .PrimaryKey(t =&gt; new { t.User_Id, t.Site_Id })
              .ForeignKey("dbo.Users", t =&gt; t.User_Id, cascadeDelete: true)
              .ForeignKey("dbo.Sites", t =&gt; t.Site_Id, cascadeDelete: true)
              .Index(t =&gt; t.User_Id)
              .Index(t =&gt; t.Site_Id);
  </code></pre>
  
  <p>Everything works well.</p>
  
  <p>Skip to today :</p>
  
  <p><strong>4th Migration</strong></p>
  
  <p>This drops the UserSites link table and creates a SiteUsers link table.</p>
  
  <p>Obviously not ideal!</p>
  
  <pre><code>public override void Up()
      {
          DropForeignKey("dbo.UserSites", "User_Id", "dbo.Users");
          DropForeignKey("dbo.UserSites", "Site_Id", "dbo.Sites");
          DropIndex("dbo.UserSites", new[] { "User_Id" });
          DropIndex("dbo.UserSites", new[] { "Site_Id" });
  
  
          CreateTable(
              "dbo.SiteUsers",
              c =&gt; new
                  {
                      Site_Id = c.Guid(nullable: false),
                      User_Id = c.Guid(nullable: false),
                  })
              .PrimaryKey(t =&gt; new { t.Site_Id, t.User_Id })
              .ForeignKey("dbo.Sites", t =&gt; t.Site_Id, cascadeDelete: true)
              .ForeignKey("dbo.Users", t =&gt; t.User_Id, cascadeDelete: true)
              .Index(t =&gt; t.Site_Id)
              .Index(t =&gt; t.User_Id);
  
          DropTable("dbo.UserSites");
  </code></pre>
  
  <p>I'm at a loss to explain this.  </p>
  
  <p>Neither class has changed since the first implementation... and I presume if I apply this I will suffer data loss.</p>
  
  <p>So to the question(s) :</p>
  
  <ol>
  <li><p>Can I just remove this code from the migration script and continue using my existing structure?</p></li>
  <li><p>Is there a gotcha that I don't know about that might have caused this?</p></li>
  </ol>
  
  <p>Any/all assistance much appreciated!</p>
  
  <p>Edit:</p>
  
  <p>I have simply defined the classes as below and allowed the model to be built by convention.  I have changed the namespace of the dbcontext, but that is all!  Colour me bewildered.</p>
  
  <pre><code>public class User
  {
     public virtual ICollection&lt;Site&gt; Sites { get; set; }
  }
  
  public class Site
  {
      public virtual ICollection&lt;User&gt; Users { get; set; }
  }
  </code></pre>