title: Entity Frame Work Core 6.0.1 is still trying to using a column I deleted from an Entity, when I add rows and Save
body: <p>Entity Frame Work Core 6.0.1 is still trying to using a column I deleted from an Entity, when I add rows and Save. I get the error:</p>
  <blockquote>
  <p>&quot;message&quot;: &quot;Invalid column name ''.\r\nInvalid column name
  'PlanTypeId'.&quot;,
  &quot;type&quot;: &quot;Microsoft.Data.SqlClient.SqlException&quot;,
  &quot;raw&quot;: &quot;Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'PlanTypeId'.\r\nInvalid column name
  'PlanTypeId'.\r\n   at
  Microsoft.Data.SqlClient.SqlCommand.&lt;&gt;c.b__188_0(Task<code>1 result)\r\n   at System.Threading.Tasks.ContinuationResultTaskFromResultTask</code>2.InnerInvoke()\r\n
  at System.Threading.Tasks.Task.&lt;&gt;c.&lt;.cctor&gt;b__271_0(Object obj)\r\n<br />
  at System.Threading.ExecutionContext.RunInternal(ExecutionContext
  executionContext, ContextCallback callback, Object state)\r\n--- End
  of stack trace from previous location ---\r\n   at
  System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp;
  currentTaskSlot, Thread threadPoolThread)\r\n--- End of stack trace
  from previous location ---\r\n   at
  Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject
  parameterObject, CancellationToken cancellationToken)\r\n   at
  Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject
  parameterObject, CancellationToken cancellationToken)\r\n   at
  Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection
  connection, CancellationToken
  cancellationToken)\r\nClientConnectionId:61d308a0-2c57-470c-9181-9bf939c8073f\r\nError
  Number:207,State:1,Class:16&quot;</p>
  </blockquote>
  <p>The entity no longer has that column PlanTypeId from the error above. ILookup is just an interface so it does not matter. The entity in question follows:</p>
  <pre><code>public class AgreementType : ILookup
  {
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      public int Id { get; set; }
      public string Code { get; set; }
      public string Name { get; set; }
      public string? Description { get; set; }
      
      [JsonIgnore]
      public virtual ICollection&lt;Fund&gt; Funds { get; set; }
      public bool Active { get; set; }
  }
  </code></pre>
  <p>The migration up code that Microsoft generated did not delete the Foreign Key column when I added the migration, so I updated the Up() code like this:</p>
  <pre><code>protected override void Up(MigrationBuilder migrationBuilder)
          {
              migrationBuilder.DropIndex(&quot;IX_AgreementTypes_PlanTypeId&quot;, &quot;AgreementTypes&quot;);
              migrationBuilder.DropForeignKey(&quot;FK_AgreementTypes_PlanTypes_PlanTypeId&quot;, &quot;AgreementTypes&quot;);
              migrationBuilder.DropColumn(&quot;PlanTypeId&quot;, &quot;AgreementTypes&quot;);
          }
  </code></pre>
  <p>When I run the Up Migration the database updates properly and the column is removed from the database. But when I try and run code to add records to the database and save I get the above error.</p>
  <pre><code>public async Task&lt;bool&gt; SeedAgreementTypesAsync(List&lt;AgreementType&gt; data)
  {
      if (!_context.AgreementTypes.Any())
      {
          await _context.AgreementTypes.AddRangeAsync(data);
          await _context.SaveChangesAsync();
          return true;
      }
      return false;
  }
  </code></pre>
  <p>It seems that Entity Framework is getting this column from somewhere, but I can't see where.</p>