title: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
body: <p>When I run the following migration, I am getting the following error: </p>
  
  <blockquote>
    <p>The ALTER TABLE statement conflicted with the FOREIGN KEY constraint </p>
  </blockquote>
  
  <p>I have an existing database and refactoring the model to include a navigation property. </p>
  
  <p>See the original model and then the new model:</p>
  
  <p>Original model:</p>
  
  <pre><code>public class Student
  {
      public int ID { get; set; }
      public string Name { get; set; }
      public string Country { get; set; }
  }
  </code></pre>
  
  <p>New model:</p>
  
  <pre><code>public class Student
  {
       public int ID { get; set; }
       public string Name { get; set; }
       public int CountryID { get; set; }
       public virtual Country Country { get; set; }
  }
  
  public class Country 
  {
       public int ID { get; set; }            
       public string Country { get; set; }
  }
  </code></pre>
  
  <p><code>Add-Migration</code> navigation property:</p>
  
  <pre><code>public override void Up()
  {
              CreateTable(
                  "dbo.Countries",
                  c =&gt; new
                      {
                          ID = c.Int(nullable: false, identity: true),
                          CountryName = c.String(),
                      })
                  .PrimaryKey(t =&gt; t.ID);
  
              AddColumn("dbo.Students", "CountryID", c =&gt; c.Int(nullable: false));
              CreateIndex("dbo.Students", "CountryID");
              AddForeignKey("dbo.Students", "CountryID", "dbo.Countries", "ID", cascadeDelete: true);
              DropColumn("dbo.Students", "Country");
  }
  </code></pre>
  
  <p><code>Update-Database</code> error:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException (0x80131904): The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.Students_dbo.Countries_CountryID". The conflict occurred in database "aspnet-navprop-20141009041805", table "dbo.Countries", column 'ID'.      </p>
  </blockquote>