The UPDATE statement conflicted with the FOREIGN KEY constraint


When I am trying to save Updated data in table using Entity Framework in ASP.NET MVC, I am getting the below error

The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_CustomerProfileV2_IndustryList". 
The conflict occurred in database "CRM", table "dbo.IndustryList", column 'IndustryName'.
The statement has been terminated.

How can i Resolve the above issue?

Here is my Current sample code

 [HttpPost]
        public ActionResult EditCustomer(long customerProfileID, CustomerProfile model)
        {
            try
            {
                //code removed 

                crmdb.Entry(model).State = System.Data.Entity.EntityState.Modified;
                crmdb.SaveChanges(); //error here

               //some code removed
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString().Replace("\n", "<br>"));
                return PartialView();
            }
        }

Any help is appreciated, thanks


Asked by:- jon
0
: 459 At:- 4/2/2018 9:33:50 AM
MVC asp.net mvc C#






1 Answers
profileImage Answered by:- manish

As per your error details "The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_CustomerProfileV2_IndustryList". The conflict occurred in database "CRM", table "dbo.IndustryList", column 'IndustryName'. The statement has been terminated."

When you are submitting forms or updating the data, You have a field related to Table dbo.IndustryList with Columns name IndustryName, which cannot be empty due to Foreign key constraint.

So to simply resolve this error provide some value for IndustryName in your form

2
At:- 4/2/2018 11:29:46 AM
Thanks, I see I had conflicts, I wasn't passing value for IndustryName using dropdown list which was required and after passing the value properly error was resolved. 0
By : jon - at :- 4/4/2018 7:19:21 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use