I am using Entity code first-migrations for my project. I already have the system up and running. However, I need to Add a new Guid column which is a foreign key. While trying to update-Database, I receive the following error:
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Categories_dbo.aspnet_Roles_RoleId". The conflict occurred in database "HelpDesk", table "dbo.aspnet_Roles", column 'RoleId'.
So I did some research and found Entity Framework 6 Code first Default value. However, I cannot figure out how to get it to set a default value for the Guid. Here is the code I tried:
Here is the migration:
public override void Up()
{
AddColumn("dbo.Categories", "RoleId", c => c.Guid(nullable: false, defaultValue: "4468ACB7-AD6F-471E-95CF-615115EA3A76"));
CreateIndex("dbo.Categories", "RoleId");
AddForeignKey("dbo.Categories", "RoleId", "dbo.aspnet_Roles", "RoleId");
}
public override void Down()
{
DropForeignKey("dbo.Categories", "RoleId", "dbo.aspnet_Roles");
DropIndex("dbo.Categories", new[] { "RoleId" });
DropColumn("dbo.Categories", "RoleId");
}
I am able to get rid of all the build errors if I switch to this code (but still gives me that Alter Table error if I run Update-database:
AddColumn("dbo.Categories", "RoleId", c => c.Guid(nullable: false, identity: false, defaultValue: null));
How do I convert this to add a specific Guid as the default value?