mysql - The INSERT statement conflicted with the FOREIGN KEY constraint2 -


the insert statement conflicted foreign key constraint "fk_job_posting_client". conflict occurred in database "resland", table "dbo.client", column 'id'. statement has been terminated.

i got above exception message while inserting data in job posting screen database design job_posting table is:

  insert [dbo].[job_posting]        ([comp_id]        ,[res_id]        ,[res_type]        ,[contact_name]        ,[contact_info]        ,[title]        ,[descr]        ,[prerequisites]        ,[skills]        ,[job_type]        ,[location]        ,[duration]        ,[post_dt]        ,[post_end_dt]        ,[positions_cnt]        ,[client_id]        ,[category]        ,[rate]        ,[perks]        ,[stat]        ,[is_deleted]        ,[cr_by]        ,[dt_cr]        ,[mod_by]        ,[dt_mod]) 

in controller wrote code :

    [validateinput(false)]      //[validateantiforgerytoken]     [httppost]     public actionresult postjob(postjobmodel model, string btn)     {          if (btn == "save")         {              job_posting jobpost = new job_posting();              jobpost.res_id = rl_constants.res_id;             jobpost.res_type = rl_constants.res_type;             jobpost.comp_id = rl_constants.comp_id;             jobpost.post_dt = convert.todatetime(model.post_dt);             jobpost.post_end_dt = convert.todatetime(model.post_end_dt);             jobpost.positions_cnt = convert.toint32(model.positions_cnts);             jobpost.job_type =convert.tostring(model.job_type);             jobpost.duration = model.duration;             jobpost.category = convert.tostring(model.category_id);             jobpost.prerequisites = model.prerequisites;             jobpost.location = model.location;             jobpost.rate = model.rate;             //client=model.client_id             //client_id=(model.client_id)             jobpost.title = model.post_title;             jobpost.descr = regex.replace(model.description, @"<[^>]+>|&nbsp;", "");              jobpost.contact_name = model.contact_person;             jobpost.contact_info = model.contact_phone + "/" + model.contact_email;             jobpost.skills = model.skills;             jobpost.perks = model.perks;             jobpost.dt_cr = datetime.now;             jobpost.cr_by = rl_constants.user_name;             jobpost.stat = "active";             jobpost.is_deleted = "n";              reslandentity.job_posting.add(jobpost);             reslandentity.savechanges();         }         return redirecttoaction("jobsearchlist", "employer");     } 

where problem

the error message says client id you're using doesn't exist in client table. setting cliendid fk reference correctly? in code you've posted setting of clientid has been commented out. means clientid = 0 (if it's int), , bet don't have clients id = 0.

---- update ----- clientid = 0 tries make fk relationship client table, fails. said didn't want use clientid @ point , clientid column nullable. i'm not sure why it's assigned 0 value, check it's working should clientid = null in mapping. should prevent ef trying make fk relationship.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -