title: .Net Core2 EF MySQL having issue while changing foreign key column to nullable
body: <p>I am working on an application where I am using .Net Core 2, EF Core and MySQL as database server via Code First approach.</p>
  
  <p>I have 2 tables:</p>
  
  <ol>
  <li>User</li>
  <li>Employee</li>
  </ol>
  
  <p>User table is the main table which contains the user information and Employee table is the child table which has a column ID_User as shown below:</p>
  
  <pre><code> public class User : BaseEntity
      {
          public int ID_User { get; set; }
          public string Name { get; set; }
          public string UserName { get; set; }
          public string Password { get; set; }
  
          public virtual ICollection&lt;Employee&gt; Employees{get;set;}
      }
  
  
  
   public class Employee : Entity
      {
          public int ID_Employee { get; set; }
          public string Name { get; set; }
  
          public int ID_User { get; set; }
  
          public virtual User User { get; set; }
      }
  </code></pre>
  
  <p>Everything works perfectly when I use the above mapping and I have enough data in both the tables.</p>
  
  <p>Now, I want to make the column <strong>ID_User</strong> in Employee table as <strong>nullable</strong></p>
  
  <p>To implement this change I made following change to my model:</p>
  
  <pre><code>public class Employee : Entity
      {
          public int ID_Employee { get; set; }
          public string Name { get; set; }
  
          public int? ID_User { get; set; }
  
          public virtual User User { get; set; }
      }
  </code></pre>
  
  <p>and in mapping file:</p>
  
  <pre><code>builder.HasOne(x=&gt;x.User).WithMany(y=&gt;y.Employees).HasForeignKey(z=&gt;z.ID_User).IsRequired(false);
  </code></pre>
  
  <p>After running the <code>dotnet ef migrations add empuser</code> command it generated the following migration code:</p>
  
  <pre><code>  migrationBuilder.DropForeignKey(
              name: "FK_Employee_User_ID_User",
              table: "Employee");
  
          migrationBuilder.AlterColumn&lt;int&gt;(
              name: "ID_User",
              table: "Employee",
              nullable: true,
              oldClrType: typeof(int));
  
          migrationBuilder.AddForeignKey(
              name: "FK_Employee_User_ID_User",
              table: "Employee",
              column: "ID_User",
              principalTable: "User",
              principalColumn: "ID_User",
              onDelete: ReferentialAction.Restrict);
  </code></pre>
  
  <p>Now when I run <code>dotnet ef database update</code> it is giving me the following error:</p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use
    near 'CONSTRAINT <code>FK_Employee_User_ID_User</code>' at line 1</p>
  </blockquote>
  
  <p>Please help.</p>
  
  <p>Thanks</p>