title: SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint
body: <p>Hello and thank you in advance for taking time to read this post. I am new to EF Core and I am attempting to setup the following database connection where I have scaffold-ed controllers from the models. </p>
  
  <pre><code>namespace VotingWebApp.Models
  {
    public class QuestionObject
    {
      public int QuestionObjectID { get; set; }
      public string Question { get; set; }
      public string AnswerA { get; set; }
      public string AnswerB { get; set; }
      public int AnswerAVote { get; set; }
      public int AnswerBVote { get; set; }
      public int GroupItemID { get; set; }
      public ICollection&lt;ResponseItem&gt; ResponseItems { get; set; }
      public GroupItem GroupItem { get; set; }
    }
  }
  
  
  namespace VotingWebApp.Models
  {
      public class GroupItem
      {
          public int GroupItemID { get; set; }
          public string GroupName { get; set; }
          public int MemberCount { get; set; }
          public int Host { get; set; }
          public ICollection&lt;GroupUserLink&gt; GroupUserLinks { get; set; }
          public ICollection&lt;QuestionObject&gt; QuestionItems { get; set; }
      }
  }
  </code></pre>
  
  <p>I receive the following error when I attempt to create a new QuestionObject in the database (Even when I supply an existing GroupItem key). </p>
  
  <blockquote>
    <p>SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_QuestionObject_GroupItem_GroupItemID". The conflict occurred in database "aspnet-VotingWebApp-02945df4-961a-4b8f-8999-19aa61dfd02e", table "dbo.GroupItem", column 'GroupItemID'.</p>
  </blockquote>
  
  <p>I am not sure how to go about solving this conflict. I have read other posts and they mainly highlight how the person is not supplying an existing key. I am new to EF Core so any help would be appreciated.</p>
  
  <pre><code>    // GET: QuestionObjects/Create
      public async Task&lt;IActionResult&gt; CreateQuestion(int? id)
      {
          if (id == null)
          {
              return NotFound();
          }
  
          var groupItem = await _context.GroupItem.SingleOrDefaultAsync(m =&gt; m.GroupItemID == id);
          if (groupItem == null)
          {
              return NotFound();
          }
          QuestionObject questionObject = new QuestionObject();
          questionObject.GroupItemID = groupItem.GroupItemID;
          return View(questionObject);
      }
  
      // POST: QuestionObjects/Create
      // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
      // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
      [HttpPost]
      [ValidateAntiForgeryToken]
      public async Task&lt;IActionResult&gt; CreateQuestion([Bind("AnswerA,AnswerAVote,AnswerB,AnswerBVote,GroupID,Question")] QuestionObject questionObject)
      {
          if (ModelState.IsValid)
          {
              _context.Add(questionObject);
              await _context.SaveChangesAsync();
              return RedirectToAction("Index");
          }
          return View(questionObject);
      }
  </code></pre>
  
  <p>I have added the code for the insertion. This is within the GroupItem controller.</p>