"ef migrations add" 总是会在新迁移中重新创建外键

4

我已经安装了带有VS 2015更新1的RC1。

每当我尝试添加一个新迁移时,同一组外键就会在Up方法中被重新创建。这意味着它们被删除然后直接重新添加。

例如,当我添加一个迁移而不改变任何模型时,会生成以下内容(显然Down方法中也会生成类似的内容):

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", table: "AspNetRoleClaims");
    migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId", table: "AspNetUserClaims");
    migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId", table: "AspNetUserLogins");
    migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_IdentityRole_RoleId", table: "AspNetUserRoles");
    migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_ApplicationUser_UserId", table: "AspNetUserRoles");
    migrationBuilder.AlterColumn<string>(
        name: "UserId",
        table: "AspNetUserLogins",
        nullable: false);
    migrationBuilder.AlterColumn<string>(
        name: "UserId",
        table: "AspNetUserClaims",
        nullable: false);
    migrationBuilder.AlterColumn<string>(
        name: "RoleId",
        table: "AspNetRoleClaims",
        nullable: false);
    migrationBuilder.AddForeignKey(
        name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",
        table: "AspNetRoleClaims",
        column: "RoleId",
        principalTable: "AspNetRoles",
        principalColumn: "Id",
        onDelete: ReferentialAction.Cascade);
    migrationBuilder.AddForeignKey(
        name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId",
        table: "AspNetUserClaims",
        column: "UserId",
        principalTable: "AspNetUsers",
        principalColumn: "Id",
        onDelete: ReferentialAction.Cascade);
    migrationBuilder.AddForeignKey(
        name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId",
        table: "AspNetUserLogins",
        column: "UserId",
        principalTable: "AspNetUsers",
        principalColumn: "Id",
        onDelete: ReferentialAction.Cascade);
    migrationBuilder.AddForeignKey(
        name: "FK_IdentityUserRole<string>_IdentityRole_RoleId",
        table: "AspNetUserRoles",
        column: "RoleId",
        principalTable: "AspNetRoles",
        principalColumn: "Id",
        onDelete: ReferentialAction.Cascade);
    migrationBuilder.AddForeignKey(
        name: "FK_IdentityUserRole<string>_ApplicationUser_UserId",
        table: "AspNetUserRoles",
        column: "UserId",
        principalTable: "AspNetUsers",
        principalColumn: "Id",
        onDelete: ReferentialAction.Cascade);
}

这是完全无用的,而且看起来在我的情况下总是发生。我在aspnet5应用程序和普通控制台应用程序中都尝试过这个。


已知问题:https://github.com/aspnet/EntityFramework/issues/3751 只需从您的 Up 和 Down 方法中删除生成的代码。 - devfric
哦,我搜索了一下,但没有找到一个未解决的问题。看起来它已经被修复了,并且修复将在rc2中发布。谢谢! - mrahhal
1个回答

3
这是一个已知问题,已经修复,修复版本将在rc2中发布。问题追踪在这里。感谢@firste的贡献。

有没有办法获取这个更新?因为它非常令人烦恼。 - Sergi0
1
老实说,我不知道。在我花费大量时间遇到EF Core(7)的巨大限制后,我最终又切换回了EF6,至少在Core成熟之前,我从未如此快乐过。目前,EF Core还不具备生产质量。 - mrahhal
顺便说一下,RC2 可能会在本月发布。 - mrahhal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接