title: INSERT statement conflicted
body: <p>This error is popular here but I have a different case here. I have the tables linked. I have data in the Department table, so the Foreign Key exists.</p>
  
  <p>Here, is the error:</p>
  
  <blockquote>
    <p>The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.Department_Department_Id". The conflict occurred in database "aspnet-hr_pcms-20181109102923", table "dbo.Department", column 'Department_Id'.</p>
    
    <p>Source Error: </p>
    
    <p>Line 153:   {<br>
    Line 154:       var user = new ApplicationUser { UserName = model.Email, Email = model.Email };<br>
    Line 155:       var result = await UserManager.CreateAsync(user, model.Password);<br>
    Line 156:       if (result.Succeeded)<br>
    Line 157:       {  </p>
  </blockquote>
  
  <p>The main error is in line 155</p>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>[SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.Department_Department_Id". The conflict occurred in database "aspnet-hr_pcms-20181109102923", table "dbo.Department", column 'Department_Id'.</p>
    
    <p>System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action<code>1 wrapCloseInAction) +2555674
           System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action</code>1 wrapCloseInAction) +5958364
           System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +285
           System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady) +4169
           System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) +255
           System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader(Boolean isInternal, Boolean forDescribeParameterEncryption) +262
           System.Data.SqlClient.SqlCommand.InternalEndExecuteNonQuery(IAsyncResult asyncResult, String endMethod, Boolean isInternal) +652
           System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult) +245
           System.Data.SqlClient.SqlCommand.EndExecuteNonQueryAsync(IAsyncResult asyncResult) +156
           System.Threading.Tasks.TaskFactory<code>1.FromAsyncCoreLogic(IAsyncResult iar, Func</code>2 endFunction, Action<code>1 endAction, Task</code>1 promise, Boolean requiresSynchronization) +86
           System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
           System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
           System.Data.Entity.Utilities.CultureAwaiter`1.GetResult() +38
           System.Data.Entity.Core.Mapping.Update.Internal.d__0.MoveNext() +2714
           System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
           System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
           System.Data.Entity.Core.Mapping.Update.Internal.d__0.MoveNext() +417</p>
  </blockquote>
  
  <pre><code>[UpdateException: An error occurred while updating the entries. See the inner exception for details.]
     System.Data.Entity.Core.Mapping.Update.Internal.&lt;UpdateAsync&gt;d__0.MoveNext() +640
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Data.Entity.Core.Objects.&lt;ExecuteInTransactionAsync&gt;d__3d`1.MoveNext() +741
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Data.Entity.Core.Objects.&lt;SaveChangesToStoreAsync&gt;d__39.MoveNext() +379
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Data.Entity.SqlServer.&lt;ExecuteAsyncImplementation&gt;d__9`1.MoveNext() +346
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Data.Entity.Core.Objects.&lt;SaveChangesInternalAsync&gt;d__31.MoveNext() +799
  
  [DbUpdateException: An error occurred while updating the entries. See the inner exception for details.]
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.AspNet.Identity.EntityFramework.&lt;SaveChanges&gt;d__61.MoveNext() +214
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.AspNet.Identity.EntityFramework.&lt;CreateAsync&gt;d__38.MoveNext() +243
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +25
     Microsoft.AspNet.Identity.&lt;CreateAsync&gt;d__73.MoveNext() +1050
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     Microsoft.AspNet.Identity.&lt;CreateAsync&gt;d__79.MoveNext() +442
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28
     hr_pcms.Controllers.&lt;Register&gt;d__15.MoveNext() in C:\Users\Administrator\source\repos\hr_pcms\hr_pcms\Controllers\AccountController.cs:155
     System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
     System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
     System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass8_0.&lt;BeginInvokeAsynchronousActionMethod&gt;b__1(IAsyncResult asyncResult) +17
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
     System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__11_0() +50
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass11_1.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__2() +228
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass7_0.&lt;BeginInvokeActionMethodWithFilters&gt;b__1(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass3_6.&lt;BeginInvokeAction&gt;b__3() +35
     System.Web.Mvc.Async.&lt;&gt;c__DisplayClass3_1.&lt;BeginInvokeAction&gt;b__5(IAsyncResult asyncResult) +100
     System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
     System.Web.Mvc.&lt;&gt;c.&lt;BeginExecuteCore&gt;b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
     System.Web.Mvc.&lt;&gt;c.&lt;BeginExecute&gt;b__151_2(IAsyncResult asyncResult, Controller controller) +13
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
     System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
     System.Web.Mvc.&lt;&gt;c.&lt;BeginProcessRequest&gt;b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
     System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
     System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
     System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
     System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +152
     System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +125
  </code></pre>
  
  <p>With this application I used, selected the Individual Authentication. I never edit the AccountController, But I expanded the Model by adding columns to the AspNetUsers Table.</p>
  
  <p>Any helpful suggestion would be great.</p>