You cannot do this with automatic migration. You will need to create the migration using Add-Migration , and then modify it so that it only modifies PK.
Migration can be simple:
public partial class TheMigration : DbMigration { public override void Up() { DropPrimaryKey("Products", new[] { "Store", "Sku" }); AddPrimaryKey("Products", "Sku"); } public override void Down() { DropPrimaryKey("Products", new[] { "Sku" }); AddPrimaryKey("Products", new[] { "Store", "Sku" }); } }
EF modifies the column because when it is part of Key , it is implicitly NOT NULL . You can leave it as it is, add the [Required] attribute, or allow EF to change the columns after , dropping the PK.
Diego mijelshon
source share