Vb.net 在向现有关系添加导航属性时,如何修复重复的外键?

Vb.net 在向现有关系添加导航属性时,如何修复重复的外键?,vb.net,entity-framework,asp.net-mvc-5,entity-framework-migrations,navigation-properties,Vb.net,Entity Framework,Asp.net Mvc 5,Entity Framework Migrations,Navigation Properties,我有一个非常简单的标识对象: Public Class UserRole Inherits IdentityUserRole(Of Integer) End Class 默认情况下,这将生成以下迁移: CreateTable( "dbo.UserRoles", Function(c) New With { .UserId = c.Int(nullable := False), .RoleId = c.In

我有一个非常简单的标识对象:

Public Class UserRole
    Inherits IdentityUserRole(Of Integer)
End Class
默认情况下,这将生成以下迁移:

 CreateTable(
    "dbo.UserRoles",
    Function(c) New With
        {
            .UserId = c.Int(nullable := False),
            .RoleId = c.Int(nullable := False)
        }) _
    .PrimaryKey(Function(t) New With { t.UserId, t.RoleId }) _
    .ForeignKey("dbo.Users", Function(t) t.UserId) _
    .ForeignKey("dbo.Roles", Function(t) t.RoleId) _
    .Index(Function(t) t.UserId) _
    .Index(Function(t) t.RoleId)
Public Overrides Sub Up()
    AddForeignKey("dbo.UserRoles", "RoleId", "dbo.Roles", "Id")
End Sub
Roles表存在一个外键,但我没有为UserRole.Role定义导航属性,对象上不存在一个

当我尝试添加一个时:

Public Class UserRole
    Inherits IdentityUserRole(Of Integer)

    Public Overridable Property Role() as Role
End Class
这将生成以下迁移:

 CreateTable(
    "dbo.UserRoles",
    Function(c) New With
        {
            .UserId = c.Int(nullable := False),
            .RoleId = c.Int(nullable := False)
        }) _
    .PrimaryKey(Function(t) New With { t.UserId, t.RoleId }) _
    .ForeignKey("dbo.Users", Function(t) t.UserId) _
    .ForeignKey("dbo.Roles", Function(t) t.RoleId) _
    .Index(Function(t) t.UserId) _
    .Index(Function(t) t.RoleId)
Public Overrides Sub Up()
    AddForeignKey("dbo.UserRoles", "RoleId", "dbo.Roles", "Id")
End Sub
然后,站点在尝试迁移时抛出错误:

System.Data.SqlClient.SqlException(0x80131904):数据库中已存在名为“FK_dbo.UserRoles_dbo.Roles_RoleId”的对象。 无法创建约束或索引

为什么它试图第二次生成外键?它不应该从初始迁移中看到现有的外键吗

我能做些什么来解决这个问题吗