title: MySql.Data.MySqlClient.MySqlException: Duplicate entry
body: <p>How is it possible to get duplicate entry error from this <strong>auto scaffold</strong> from .net identity code:</p>
  
  <pre><code>        public async Task&lt;IActionResult&gt; OnPostAsync(string returnUrl = null)
          {
              returnUrl = returnUrl ?? Url.Content("~/");
              if (ModelState.IsValid)
              {
                  var user = new ApplicationUser {  UserName = Input.Email, Email = Input.Email };
                  var result = await _userManager.CreateAsync(user, Input.Password);
                  if (result.Succeeded)
                  {
                      _logger.LogInformation("User created a new account with password.");
  
                      var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                      var callbackUrl = Url.Page(
                          "/Account/ConfirmEmail",
                          pageHandler: null,
                          values: new { userId = user.Id, code = code },
                          protocol: Request.Scheme);
  
                      await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                          $"Please confirm your account by &lt;a href='{HtmlEncoder.Default.Encode(callbackUrl)}'&gt;clicking here&lt;/a&gt;.");
  
                      await _signInManager.SignInAsync(user, isPersistent: false);
                      return LocalRedirect(returnUrl);
                  }
                  foreach (var error in result.Errors)
                  {
                      ModelState.AddModelError(string.Empty, error.Description);
                  }
              }
  
              // If we got this far, something failed, redisplay form
              return Page();
          }
  </code></pre>
  
  <p>Produces this stacktrace:</p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
          An unhandled exception has occurred while executing the request.
    Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry '3ab1a765-c575-4a50-ba42-6d282ccb24a6' for key 'PRIMARY' ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry '3ab1a765-c575-4a50-ba42-6d282ccb24a6' for key 'PRIMARY'
       at MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task<code>1 task) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 1252
       at System.Threading.Tasks.ContinuationResultTaskFromResultTask</code>2.InnerInvoke()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&amp; currentTaskSlot)
    --- End of stack trace from previous location where exception was thrown ---
       at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
       --- End of inner exception stack trace ---
       at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 81
       at MySql.Data.MySqlClient.MySqlDataReader.ReadFirstResultSetAsync(IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 307
       at MySql.Data.MySqlClient.MySqlDataReader.CreateAsync(MySqlCommand command, CommandBehavior behavior, ResultSetProtocol resultSetProtocol, IOBehavior ioBehavior) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 292
       at MySqlConnector.Core.TextCommandExecutor.ExecuteReaderAsync(String commandText, MySqlParameterCollection parameterCollection, CommandBehavior behavior, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 37
       at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary<code>2 parameterValues, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       --- End of inner exception stack trace ---
       at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(DbContext _, ValueTuple</code>2 parameters, CancellationToken cancellationToken)
       at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func<code>4 operation, Func</code>4 verifySucceeded, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IReadOnlyList<code>1 entriesToSave, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
       at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore</code>9.CreateAsync(TUser user, CancellationToken cancellationToken)
       at Chuchubi.Data.MultiTenant.TenantUserStore.CreateAsync(ApplicationUser user, CancellationToken cancellationToken) in C:\Users\Dropbox\Code\chuchubi-backend\Chuchubi.Data\MultiTenant\TenantUserStore.cs:line 30
       at Microsoft.AspNetCore.Identity.UserManager<code>1.CreateAsync(TUser user)
       at Microsoft.AspNetCore.Identity.UserManager</code>1.CreateAsync(TUser user, String password)
       at Chuchubi.Areas.Identity.Pages.Account.RegisterModel.OnPostAsync(String returnUrl) in C:\Users\Dropbox\Code\chuchubi-backend\Chuchubi\Areas\Identity\Pages\Account\Register.cshtml.cs:line 71
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.ExecutorFactory.GenericTaskHandlerMethod.Convert[T](Object taskAsObject)
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.ExecutorFactory.GenericTaskHandlerMethod.Execute(Object receiver, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeHandlerMethodAsync()
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeNextPageFilterAsync()
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
       at Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker.InvokeInnerFilterAsync()
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
       at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
       at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
       at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
       at SaasKit.Multitenancy.Internal.TenantResolutionMiddleware<code>1.Invoke(HttpContext context, ITenantResolver</code>1 tenantResolver)
       at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
       at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
       at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware.Invoke(HttpContext httpContext)
       at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]</p>
  </blockquote>
  
  <p>This was from auto generated code from visual studio.</p>
  
  <p>EDIT: </p>
  
  <p>MySql version details:</p>
  
  <pre><code>'immediate_server_version', '999999'
  'innodb_version', '8.0.16'
  'original_server_version', '999999'
  'protocol_version', '10'
  'slave_type_conversions', ''
  'tls_version', 'TLSv1,TLSv1.1,TLSv1.2'
  'version', '8.0.16'
  'version_comment', 'MySQL Community Server - GPL'
  'version_compile_machine', 'x86_64'
  'version_compile_os', 'Win64'
  'version_compile_zlib', '1.2.11'
  </code></pre>
  
  <p>my csproj:</p>
  
  <pre><code>    &lt;PackageReference Include="Microsoft.AspNetCore.App" /&gt;
      &lt;PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /&gt;
      &lt;PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" /&gt;
      &lt;PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" /&gt;
      &lt;PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" /&gt;
      &lt;PackageReference Include="Pomelo.EntityFrameworkCore.MySql.Design" Version="1.1.2" /&gt;
      &lt;PackageReference Include="SaasKit.Multitenancy" Version="1.1.4" /&gt;
  </code></pre>
  
  <p>This is done on a empty database, after the error there is no user being inserted in the database!</p>