given the class:
public class Product
{
public int Id { get; set; }
virtual PropertiesTemplate PropertiesTemplate { get; set; }
}
when I added explicit foreign key property
public int PropertiesTemplateId { get; set; }
I expected migrations to mark that field in database as not nullable. Instead of that migrations produced code that only renames the column:
public override void Up()
{
DropForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates");
DropIndex("dbo.Products", new[] { "PropertiesTemplate_Id" });
RenameColumn(table: "dbo.Products", name: "PropertiesTemplate_Id", newName: "PropertiesTemplateId");
AddForeignKey("dbo.Products", "PropertiesTemplateId", "dbo.PropertiesTemplates", "Id", cascadeDelete: true);
CreateIndex("dbo.Products", "PropertiesTemplateId");
}
if instead of adding int property I tag PropertiesTemplate with [Required] attribute, migrations does the right thing and marks it as non nullable
public override void Up()
{
DropForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates");
DropIndex("dbo.Products", new[] { "PropertiesTemplate_Id" });
AlterColumn("dbo.Products", "PropertiesTemplate_Id", c => c.Int(nullable: false));
AddForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates", "Id", cascadeDelete: true);
CreateIndex("dbo.Products", "PropertiesTemplate_Id");
}
public class Product
{
public int Id { get; set; }
virtual PropertiesTemplate PropertiesTemplate { get; set; }
}
when I added explicit foreign key property
public int PropertiesTemplateId { get; set; }
I expected migrations to mark that field in database as not nullable. Instead of that migrations produced code that only renames the column:
public override void Up()
{
DropForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates");
DropIndex("dbo.Products", new[] { "PropertiesTemplate_Id" });
RenameColumn(table: "dbo.Products", name: "PropertiesTemplate_Id", newName: "PropertiesTemplateId");
AddForeignKey("dbo.Products", "PropertiesTemplateId", "dbo.PropertiesTemplates", "Id", cascadeDelete: true);
CreateIndex("dbo.Products", "PropertiesTemplateId");
}
if instead of adding int property I tag PropertiesTemplate with [Required] attribute, migrations does the right thing and marks it as non nullable
public override void Up()
{
DropForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates");
DropIndex("dbo.Products", new[] { "PropertiesTemplate_Id" });
AlterColumn("dbo.Products", "PropertiesTemplate_Id", c => c.Int(nullable: false));
AddForeignKey("dbo.Products", "PropertiesTemplate_Id", "dbo.PropertiesTemplates", "Id", cascadeDelete: true);
CreateIndex("dbo.Products", "PropertiesTemplate_Id");
}