Entity Framework: Migration falsely adds foreign key column twice
<p>I'm using <strong>EntityFramework 6.1.3</strong> with CodeFirst for an Asp.Net application. I have an existing table ("Users") on which I'm trying to add a foreign key <strong>"GroupId"</strong>. 
This is the class (Everything with //new are changes made after the last migration)</p>

<pre><code>[Table("Users")]
public class User
{
    [Key]
    [Column("PK_USER")]
    public int Id { get; set; }
    [Column("Username")]
    public string Username { get; set; }
    [Column("Name")]
    public string Name { get; set; }
    [Column("Password")]
    public string Password { get; set; }
    [Column("Firstname")]
    public string Firstname { get; set; }
    [Column("Lastname")]
    public string Lastname { get; set; }
    [Column("LastLogin")]
    public DateTime? LastLogin { get; set; }
    [Column("Department")]
    public string Department { get; set; }
    [Column("EMail")]
    public string EMail { get; set; }
    [Column("IsWindowsUser")]
    public bool? IsWindowsUser { get; set; }
    [Column("Signature")]
    public string Signature { get; set; }

    [Column("FK_ROLE")]
    public int? RoleId { get; set; }
    [ForeignKey("RoleId")]
    public virtual Role Role { get; set; }

    // new
    [Column("GroupId")]
    public int? GroupId { get; set; }

    //new
    [ForeignKey("GroupId")]
    public virtual Group Group { get; set; }

    //new
    public virtual ICollection&lt;GroupResponsibility&gt; Responsibilites { get; set; }

    public virtual ICollection&lt;UserField&gt; UserFields { get; set; }

    public override string ToString()
    {
        return Username;
    }

}
</code></pre>

<p>After I run <strong>add-migration</strong> the following code is generated (omitted other changes)</p>

<pre><code>        AddColumn("dbo.Users", "GroupId", c =&gt; c.Int());
        AddColumn("dbo.Users", "Group_Id", c =&gt; c.Int());
        CreateIndex("dbo.Users", "GroupId");
        CreateIndex("dbo.Users", "Group_Id");
        AddForeignKey("dbo.Users", "Group_Id", "dbo.Groups", "Id");
        AddForeignKey("dbo.Users", "GroupId", "dbo.Groups", "Id");
</code></pre>

<p>As you can see EntityFramework recognized the foreign key but still added a default one "Group_Id". If I go through with it, and update the database, the navigational property "Group" will releate to "Group_Id" instead of the desired "GroupId".</p>

<p>Any ideas what might cause this?</p>

<h1>Update 1</h1>

<p>I commented out the navigational property and got the same result. Looks like the ICollection <strong>Users</strong> on the other end of the relation is the culprit. Here is the class <strong>"Group"</strong></p>

<pre><code>[Table("Groups")]
public class Group
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public int? GroupLeaderId { get; set; }

    [ForeignKey("GroupLeaderId")]
    public virtual User GroupLeader { get; set; }

    public virtual ICollection&lt;User&gt; Users { get; set; }
    public virtual ICollection&lt;GroupResponsibility&gt; Responsibilites { get; set; }
    public virtual ICollection&lt;ApplicationForm&gt; Applications { get; set; }

    public override string ToString()
    {
        return Name;
    }
}
</code></pre>

<p>If I <strong>comment out</strong> the ICollection <strong>Users</strong>, I get the following exception when adding the migration:</p>

<blockquote>
  <p>Unable to determine the principal end of an association between the types 'SparePartsDb.Entities.Group' and 'SparePartsDb.Entities.User'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.</p>
</blockquote>

<h1>Update 2</h1>

<p>After some googling and changing the Key Attribute on the Group class...</p>

<pre><code>    [Key, ForeignKey("GroupLeader")]
    public int Id { get; set; }
</code></pre>

<p>...I'm able to comment out the ICollection and run the migration. However, GroupId is not not longer recognized as a foreign key even though the navigiational property is present in the class User.</p>

<pre><code>AddColumn("dbo.Users", "GroupId", c =&gt; c.Int());
</code></pre>