Code:
migrationBuilder.AddPrimaryKey("AspNetRoles", "PK_AspNetRoles", new[] { "Id" }, isClustered: true);
I am getting the error message as Cannot define PRIMARY KEY constraint on nullable column in table 'AspNetRoles'.
Namespace of MigrationBuilder - Microsoft.Data.Entity.Relational.Migrations.Builders
How to assign NOT NULL
to the above code in ASP.NET MVC 6
For a very temporary workaround to be able to write some code-first EF entities and advance, I commented out the part of the migration script dealing with those keys.
Obviously this butchers the relations in the ASP.NET users and roles tables and isn't a workable long term solution, I assume it will be fixed or someone will find a real solution at some point.
Some of the lines I commented out (I got the same error with Users once I changed Roles).
//migrationBuilder.AddPrimaryKey("AspNetRoles", "PK_AspNetRoles", new[] { "Id" }, isClustered: true);
//migrationBuilder.AddPrimaryKey("AspNetUsers", "PK_AspNetUsers", new[] { "Id" }, isClustered: true);
....
//migrationBuilder.AddForeignKey(
// "AspNetRoleClaims",
// "FK_AspNetRoleClaims_AspNetRoles_RoleId",
// new[] { "RoleId" },
// "AspNetRoles",
// new[] { "Id" },
// cascadeDelete: false);
//migrationBuilder.AddForeignKey(
// "AspNetUserClaims",
// "FK_AspNetUserClaims_AspNetUsers_UserId",
// new[] { "UserId" },
// "AspNetUsers",
// new[] { "Id" },
// cascadeDelete: false);
//migrationBuilder.AddForeignKey(
// "AspNetUserLogins",
// "FK_AspNetUserLogins_AspNetUsers_UserId",
// new[] { "UserId" },
// "AspNetUsers",
// new[] { "Id" },
// cascadeDelete: false);
...
//migrationBuilder.DropForeignKey("AspNetRoleClaims", "FK_AspNetRoleClaims_AspNetRoles_RoleId");
//migrationBuilder.DropPrimaryKey("AspNetRoles", "PK_AspNetRoles");
//migrationBuilder.AddForeignKey(
// "AspNetRoleClaims",
// "FK_AspNetRoleClaims_AspNetRoles_RoleId",
// new[] { "RoleId" },
// "AspNetRoles",
// new[] { "Id" },
// cascadeDelete: false);
//migrationBuilder.AddForeignKey(
// "AspNetUserLogins",
// "FK_AspNetUserLogins_AspNetUsers_UserId",
// new[] { "UserId" },
// "AspNetUsers",
// new[] { "Id" },
// cascadeDelete: false);
This is presumably a bug or missing feature in the very early build of EF7?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With