Entity Framework 5 Multiple identity columns specified for table. Only one identity column per table is allowed

I encountered the same error when trying to rename a Key column. To make the migration work, I had to reorder the order of operations in my scaffolded migration script.

Here, I made sure to order the Drop operations first, then added the new Key field afterwards.

public partial class RenameKey : DbMigration
{
    public override void Up()
    {
        DropPrimaryKey("dbo.GameSummary", new[] { "OldId" });
        DropColumn("dbo.GameSummary", "OldId");
        AddColumn("dbo.GameSummary", "Id", c => c.Int(nullable: false, identity: true));
        AddPrimaryKey("dbo.GameSummary", "Id");
    }

Hope that helps with your case.


I also didn't have any problem simply replacing the relevant DropPrimaryKey, DropColumn, AddColumn and AddPrimaryKey commands with a RenameColumn command, e.g.

public partial class RenameKey : DbMigration
{
    public override void Up()
    {    
        RenameColumn("dbo.GameSummary", "OldId", "Id");
    }
}

I also had a similar problem after my first migrations. What I realized was that after I deleted the database which the first migration created and then too removed the migrations folder created in my mvc application, the problem did not appear again.