title: Entity Framework The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
body: <p>On updating database in Entity Framework , Code first Migration, I am getting this error:</p>
  
  <blockquote>
    <p>The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Clients_dbo.MedicalGroups_MedicalGroupId". The conflict occurred in database "hrbc", table "dbo.MedicalGroups", column 'Id'.</p>
  </blockquote>
  
  <p>This is my class:</p>
  
  <pre><code>public partial class Client
  {
      [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public int? MedicalGroupId { get; set; }
      [ForeignKey("MedicalGroupId")]
      public virtual MedicalGroups MedicalGroup { get { return _MedicalGroup; } set { _MedicalGroup = value; } }
  }
  </code></pre>
  
  <p>Here is my 2nd class:</p>
  
  <pre><code>public partial class MedicalGroups
  {
      [Key]
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>And this is my migration which I am trying to apply:</p>
  
  <pre><code>public override void Up()
  {
      AddForeignKey("dbo.Clients", "MedicalGroupId", "dbo.MedicalGroups", "Id");
      CreateIndex("dbo.Clients", "MedicalGroupId");
  }
  </code></pre>