title: How do I create a Foreign Key in EF6
body: <p>I have two db classes defined as shown below</p>
  <pre><code>[Table(&quot;Warehouses&quot;)]
  public class Warehouse : FullAuditedEntity, IMustHaveTenant
  {
      public virtual int TenantId { get; set; }
  
      [Required]
      [MaxLength(255)]
      public string Name { get; set; }
  
      public virtual WarehouseAddress Address { get; set; }
      [ForeignKey(&quot;FKWarehouseAddressId&quot;)]
      public int AddressId { get; set; }
  
  }
  </code></pre>
  <p>and</p>
  <pre><code>[Table(&quot;Customers&quot;)]
  public class Customer : FullAuditedEntity, IMustHaveTenant
  {
      public virtual int TenantId { get; set; }
      public virtual Warehouse Warehouse { get; set; }
      [ForeignKey(&quot;FK_WarehouseId&quot;)]
      public int WarehouseId { get; set; }
  
      [Required]
      [MaxLength(255)]
      public string CustomerName { get; set; }
  
      public virtual DistributionRoute DistributionRoute { get; set; }
      [ForeignKey(&quot;FKRouteId&quot;)]
      public int RouteId { get; set; }
  
      public virtual CustomerAddress CustomerAddress { get; set; }
      [ForeignKey(&quot;FKAddressId&quot;)]
      public int AddressId { get; set; }
  }
  </code></pre>
  <p>What I want is for every record in Customers table to have a WarehouseId column which refers to the Id column in Warehouses table. I ama not sure where I am getting it wrong because for the RouteId column which is in DistributionRoute table it works fine. Can someone help. When I try to update my database I am getting the error below:</p>
  <p><em>The ALTER TABLE statement conflicted with the FOREIGN KEY constraint &quot;FK_Customers_Warehouses_WarehouseId&quot;. The conflict occurred in database &quot;StoreDb&quot;, table &quot;dbo.Warehouses&quot;, column 'Id'.</em></p>