“ef migrations add”始终在新迁移中重新创建外键

2024-05-01

我安装了 RC1 和 VS 2015 update 1。

每当我尝试添加新的迁移时,都会在 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 应用程序和普通控制台应用程序中尝试过此操作。


这是一个已知问题,并且已经修复,修复即将针对 rc2。该问题已被追踪here https://github.com/aspnet/EntityFramework/issues/3751.

谢谢@firste。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“ef migrations add”始终在新迁移中重新创建外键 的相关文章

随机推荐