简体   繁体   English

更新实体框架时出错

[英]Getting Error On Updating Entity Framework

I am getting an error during DBUpdation Exception exception of a particular entry in the table. 表中特定条目的DBUpdation Exception异常期间出现错误。

Cannot add or update a child row: a foreign key constraint fails, however the USerID exist in appuser table. 无法添加或更新子行:外键约束失败,但是appuser表中存在USerID。

First I will update one of the column to false, then add a new entry to the table for the same userID. 首先,我将其中一列更新为false,然后将相同的userID添加到表中。 The same code is working fine in local environment. 相同的代码在本地环境中运行良好。

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Cannot add or update a child row: a foreign key constraint fails (`asd34556`.`freeattribute`, CONSTRAINT `FK_FreeAttr_UserID_ApUser_UserID` FOREIGN KEY (`UserID`) REFERENCES `appuser` (`UserID`) ON DELETE NO ACTION ON UPDATE NO ACTION)
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at FreeLance.Business.ProfileManagement.ProfileManagementBC.UpdateOtherDetails(appuser user)
at FreeLance.Web.Controllers.ManageProfileController.OtherInfoUpdate(ProfileModel model)
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)

Here the important info is: 这里的重要信息是:

  • It Works locally 它在本地工作
  • The error is a Foreign key constraint related to the Appuser 该错误是与Appuser相关的外键约束

Therefore problem probably is: 因此问题可能是:

  • On the remoted server you accessing the user using an appuser that is not registered in the Remote database. 在远程服务器上,您使用未在远程数据库中注册的appuser访问用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM