【问题标题】:"ef migrations add" always recreates foreign keys in the new migration“ef migrations add”总是在新迁移中重新创建外键
【发布时间】:2015-12-04 19:04:32
【问题描述】:

我已经安装了 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 应用程序和一个普通的控制台应用程序中都试过这个。

【问题讨论】:

  • 已知问题:github.com/aspnet/EntityFramework/issues/3751 只需删除从您的 Up 和 Down 方法生成的代码即可。
  • 哦,我搜索了但没有找到未解决的问题。看来它已经修复了,并且修复即将针对 rc2 进行。谢谢!

标签: entity-framework-core


【解决方案1】:

这是一个已知问题,已经修复,即将针对 rc2 进行修复。该问题已被跟踪here

谢谢@firste。

【讨论】:

  • 有没有办法获得这个更新?因为它很烦人
  • 我真的不知道。在我花了很多时间在 EF Core (7) 上遇到巨大的限制之后,我终于再次切换到 EF6,至少在 Core 成熟之前,我的生活中从未如此快乐过。 EF Core 现在只是不具备生产质量。
  • RC2 可能会在本月推出 BTW。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-18
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
相关资源
最近更新 更多