title: How to Drop Unique Constraint with code-first migration in asp.net-core
body: <p>I have a project for which I added an initial migration with a foreign key as follows:</p>
  <pre><code> public class ApplicationUser : IdentityUser 
   {
    public string RegistrarId { get; set; }
   
    [ForeignKey(&quot;RegistrarId&quot;)]
    public virtual ApplicationUser Registrar { get; set; }
  
   }
  </code></pre>
  <p>However, I realized that when I run the code-first migration, it is automatically creating a unique index on the Registrar column which is against my wish.</p>
  <pre><code> migrationBuilder.CreateIndex(
              name: &quot;IX_AspNetUsers_RegistrarId&quot;,
              table: &quot;AspNetUsers&quot;,
              column: &quot;RegistrarId&quot;,
              unique: true,
              filter: &quot;[RegistrarId] IS NOT NULL&quot;);
  </code></pre>
  <p>My question is, Is there a way to modify my class to remove this constraint with another migration.</p>
  <p>Below is what I have for the ApplicationUser entity onModelCreating</p>
  <pre><code> protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          modelBuilder.Entity&lt;ApplicationUser&gt;(b =&gt;
          {
              // Each User can have many UserClaims
              b.HasMany(e =&gt; e.Claims)
                  .WithOne(e =&gt; e.User)
                  .HasForeignKey(uc =&gt; uc.UserId)
                  .IsRequired();
  
              // Each User can have many UserLogins
              b.HasMany(e =&gt; e.Logins)
                  .WithOne(e =&gt; e.User)
                  .HasForeignKey(ul =&gt; ul.UserId)
                  .IsRequired();
  
              // Each User can have many UserTokens
              b.HasMany(e =&gt; e.Tokens)
                  .WithOne(e =&gt; e.User)
                  .HasForeignKey(ut =&gt; ut.UserId)
                  .IsRequired();
  
              // Each User can have many entries in the UserRole join table
              b.HasMany(e =&gt; e.UserRoles)
                  .WithOne(e =&gt; e.User)
                  .HasForeignKey(ur =&gt; ur.UserId)
                  .IsRequired();
  
              b.HasIndex(e =&gt; e.Email)
                  .IsUnique();             
          });
  </code></pre>
  <p>My application is on ASP.NET-Core 3.1 with EF-Core 3.1 and SQLServer</p>
  <p>Please help
  Thank you</p>