Entity Framework change Key Type

I would expect that the generated migration is using AlterColumn to try and change the type of the field from guid to int. This is not possible, so you'll need to modify the generated migration yourself:

Assuming your table is dbo.People and the key is called Id, you probably have this at the moment:

DropPrimaryKey("dbo.People");
AlterColumn("dbo.People", "Id", c => c.Int(nullable: false, identity: true));
AddPrimaryKey("dbo.People", "Id");

Change it to:

DropPrimaryKey("dbo.People");
DropColumn("dbo.People", "Id");
AddColumn("dbo.People", "Id", c => c.Int(nullable: false, identity: true));
AddPrimaryKey("dbo.People", "Id");

Note that if you've got this key referenced elsewhere, this technique will not work if you've got any data present, as the keys are all being regenerated.


Update for EF Core generated migrations:

dotnet : System.Data.SqlClient.SqlException: Operand type clash: int is incompatible with uniqueidentifier

change

migrationBuilder.AlterColumn<Guid>(
            name: "VATID",
            schema: "catalogue",
            table: "Products",
            nullable: false,
            oldClrType: typeof(int));

into

        migrationBuilder.DropColumn(
            name: "VATID",
            schema: "catalogue",
            table: "Products");

        migrationBuilder.AddColumn<Guid>(
            name: "VATID",
            schema: "catalogue",
            table: "Products",
            nullable: false);

Of course, this will destroy your data for the certain column. But they obviously cannot be converted into GUID.