How can I change an int ID column to Guid with EF migration?
<p>I'm using EF code-first approach and want to change the <code>Id</code> field to <code>guid</code> but can't seem to get past below error.</p>

<p>This is my first migration:</p>

<pre><code>public partial class CreateDownloadToken : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.DownloadTokens",
            c =&gt; new
            {
                Id = c.Int(nullable: false, identity: true),
                FileId = c.Int(),
                UserId = c.String(nullable: false, maxLength: 128),
                ValidUntil = c.DateTime(nullable: false),
            })
            .PrimaryKey(t =&gt; t.Id)
            .ForeignKey("dbo.Files", t =&gt; t.FileId)
            .ForeignKey("dbo.Users", t =&gt; t.UserId, cascadeDelete: true)
            .Index(t =&gt; t.FileId)
            .Index(t =&gt; t.UserId);

    }

    public override void Down()
    {
        DropForeignKey("dbo.DownloadTokens", "UserId", "dbo.Users");
        DropForeignKey("dbo.DownloadTokens", "FileId", "dbo.Files");
        DropIndex("dbo.DownloadTokens", new[] { "UserId" });
        DropIndex("dbo.DownloadTokens", new[] { "FileId" });
        DropTable("dbo.DownloadTokens");
    }
}
</code></pre>

<p>Later I realized that I need my <code>Id</code> column to be GUID so I changed my model file: </p>

<pre><code>public class DownloadToken
{
    [Key, DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    public Guid Id { get; set; }

    public int? FileId { get; set; }

    [ForeignKey("FileId")]
    public virtual File File { get; set; }

    [Required]
    public string UserId { get; set; }

    [ForeignKey("UserId")]
    public virtual User User { get; set; }

    [Required]
    public DateTime ValidUntil { get; set; }
}
</code></pre>

<p>When running <code>Add-Migration ChangeDownloadTokenIdToGuid</code> it generates this file:</p>

<pre><code>public partial class ChangeDownloadTokenIdToGuid : DbMigration
{
    public override void Up()
    {
        DropPrimaryKey("dbo.DownloadTokens");
        AlterColumn("dbo.DownloadTokens", "Id", c =&gt; c.Guid(nullable: false));
        AddPrimaryKey("dbo.DownloadTokens", "Id");
    }

    public override void Down()
    {
        DropPrimaryKey("dbo.DownloadTokens");
        AlterColumn("dbo.DownloadTokens", "Id", c =&gt; c.Int(nullable: false, identity: true));
        AddPrimaryKey("dbo.DownloadTokens", "Id");
    }
}
</code></pre>

<p>Running this file with <code>Update-Database</code> causes this error:</p>

<pre><code>Identity column 'Id' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.
</code></pre>

<p>Any ideas why this might be happening?</p>