title: Entity Framework code-first migrations does not generate a foreign key and ignores the ForeignKey data annotation
body: <p>I am trying to add a foreign key to my database table using EF code-first migrations, but when I run <code>add-migration</code>, the <code>Up()</code> and <code>Down()</code> methods in the generated migration are empty.</p>
  <p>The base table to which the foreign key should link is <code>Reservation</code> and the table to which I am trying to add the key is <code>Batch</code>.</p>
  <p><strong>Reservation</strong> model class:</p>
  <pre><code>public class Reservation
  {
      [Key]
      public int ReservationId { get; set; }
  
      public virtual ICollection&lt;Batch&gt; Batches { get; set; }
      
      ...
  }
  </code></pre>
  <p><strong>Batch</strong> model class:</p>
  <pre><code>public class Batch
  {
     [Key]
     public int BatchId { get; set; }
     
     public int ReservationId { get; set; }
  
     [ForeignKey(&quot;ReservationId&quot;)]
     public Reservation Reservation { get; set; }
  
     ...
  }
  </code></pre>
  <p>The <code>Reservation</code> attribute was previously called <code>TempReservation</code> and did not have a <code>[ForeignKey]</code> annotation which is why the foreign key did not get created in the first place.</p>
  <p>I tried fixing it by adding the <code>[ForeignKey]</code> annotation and changing the property name to <code>Reservation</code> like in the above code snippet shows, but to no avail.</p>
  <p>The migration always ignores my changes, giving me empty <code>Up()</code> and <code>Down()</code>.</p>
  <p>I have other model classes that follow the same &quot;structure&quot; and they all have foreign keys without any issues. The only difference is that I am adding this FK after the <code>Batch</code> table was already created.</p>