On updating database in Entity Framework , Code first Migration, I am getting this error:
The ALTER TABLE statement conflicted with the FOREIGN KEY constr
this problem appear because your table is not empty.
so you shoud add the new field without attaching it like foreign key.
public int? MedicalGroupId { get; set; }
.And execute update-database
command in package manage console.
Then fill the field in this table(client) with the right data (value exists in MedicalGroupsId).
Insert the line to create the foreign key
[ForeignKey("MedicalGroupId")]
public virtual MedicalGroups MedicalGroup { get { return _MedicalGroup; } set { _MedicalGroup = value; } }
in the end execute the update-database
command. It will be ok.