title: In Code first The INSERT statement conflicted with the FOREIGN KEY constraint
body: <p>I just started using Code first approach for creating databases. I have following 3 tables :</p>
  
  <pre><code>public partial class AccountHolder
  {
      public int AccountHolderId { get; set; }
  
      public virtual List&lt;Address&gt; Address { get; set; }
  }
  
  public partial class Nominee
  {
      public int NomineeId { get; set; }
  
      public virtual List&lt;Address&gt; Address { get; set; }
  }
  
  public partial class Address
  {
      public int AddressId { get; set; }
  
      public int AccountHolderId { get; set; }
      public AccountHolder AccountHolder { get; set; }
  
      public int NomineeId { get; set; }
      public Nominee Nominee { get; set; }
  }
  </code></pre>
  
  <p>Here <code>AccountHolder</code> and <code>Nominee</code> both have <code>1 to *</code> replationship with the address. The fluent API code which i used for this is :</p>
  
  <pre><code>    protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Address&gt;().HasRequired(p =&gt; p.AccountHolder)
                                        .WithMany(p =&gt; p.Address)
                                        .HasForeignKey(p =&gt; p.AccountHolderId)
                                        .WillCascadeOnDelete(false);
          modelBuilder.Entity&lt;Address&gt;().HasRequired(p =&gt; p.Nominee) 
                                        .WithMany(p =&gt; p.Address)
                                        .HasForeignKey(p =&gt; p.NomineeId)
                                        .WillCascadeOnDelete(false);
      }
  </code></pre>
  
  <p>Now my issue is whenever i am trying to insert data in AccountHolder or Nominee i got this exception :</p>
  
  <p><em>In case of AccountHolder insertion</em></p>
  
  <blockquote>
    <p>{"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_dbo.Addresses_dbo.Nominees_NomineeId\". The conflict occurred in database \"CodeFirst.BankContext\", table \"dbo.Nominees\", column 'NomineeId'.\r\nThe statement has been terminated."}</p>
  </blockquote>
  
  <p><em>In case of Nominee insertion</em></p>
  
  <blockquote>
    <p>{"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_dbo.Addresses_dbo.AccountHolders_AccountHolderId\". The conflict occurred in database \"CodeFirst.BankContext\", table \"dbo.AccountHolders\", column 'AccountHolderId'.\r\nThe statement has been terminated."}</p>
  </blockquote>
  
  <p>Cananybody please tell me how to solve this issue and what i am missing here ?</p>