“ef migrations add”總是在新遷移中重新創建外鍵


我安裝了RC 2015和VS 2015更新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。這個問題在這裡被跟踪。

謝謝@firste。





許可下: CC-BY-SA
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因