1
I have the following scenario
public class branch()
{
    public Branch()
    {
        Branchs = new HashSet<Branch>();
    }
    [StringLength(80)]
    public string Description { get; set; }
    [Required]
    [ForeignKey("TypeDelivery")]
    public long TypeDeliveryId { get;set; }
    public virtual TypeDelivery TypeDeliverys { get; set; }
}
public class TypeDelivery()
{
    public TypeDelivery()
    {
        Branchs = new HashSet<Branch>();
    }
    [StringLength(80)]
    public string Description { get; set; }
    public virtual ICollection<Branch> Branchs { get; set; }
}
but when I run update-database on Migrations it returns the following error.
Error Number:547,State:0,Class:16
The ALTER TABLE statement conflicted with the FOREIGN KEY Constraint "Fk_dbo.Branches_dbo.Typedeliveries_typedeliveryid". The Conflict occurred in database "Pensouchegouproducao", table "dbo.Typedeliveries", column 'Id'.
if anyone has passed by so help me please.
Follow the migration file.
public override void Up()
{
    AddColumn("dbo.Branches", "TypeDeliveryId", c => c.Long(nullable: false));
    CreateIndex("dbo.Branches", "TypeDeliveryId");
    AddForeignKey("dbo.Branches", "TypeDeliveryId", "dbo.TypeDeliveries", "Id");
}
public override void Down()
{
    DropForeignKey("dbo.Branches", "TypeDeliveryId", "dbo.TypeDeliveries");
    DropIndex("dbo.Branches", new[] { "TypeDeliveryId" });
    DropColumn("dbo.Branches", "TypeDeliveryId");
}
						
Can I post the contents of the Migration file? Or are you updating directly, without using explicit migrations?
– Jéf Bueno
ready updated in question
– Thiago Ubiratan
Data already exists in the table
Branches, right?– Jéf Bueno
yes I already have data in it
– Thiago Ubiratan
Well, just see my answer.
– Jéf Bueno