title: The UPDATE statement conflicted with the FOREIGN KEY constraint
body: <p>Recently I tried to add a one-to-many relationship in my MVC application via Entity Framework Code First.  I added the relationship to bind an Administrator name from a dropdown list to the current application that is being filled out.  So I have one table for the administrator names and one for the actual application information. The application and dropdown list of admin names seem to work fine and all information is going into my database on submit, but when I try to Edit the application, I get the following error:</p>
  
  <blockquote>
    <p>The UPDATE statement conflicted with the FOREIGN KEY constraint The conflict occurred in database table "dbo.Administrator", column 'AdministratorId'</p>
  </blockquote>
  
  <p>I've tried setting my Id columns to "Not Null", but this did not solve the issue. </p>
  
  <p>Model: </p>
  
  <pre><code>public class Administrator
  {
  
      public int AdministratorId{ get; set; }
      public string AdministratorName{ get; set; }
  
  }
  
  public class Application
  {
      public Application()
      {
          GetDate = DateTime.Now;
      }
  
      public int ApplicationId { get; set; }
  
      [DisplayName("Marital Status")]
      public bool? MaritalStatus { get; set; }
  
      [Required]
      [DisplayName("First Name")]
      public string FirstName { get; set; }
  
      [DisplayName("Middle Initial")]
      public string MiddleInitial { get; set; }
       [Required]
      [DisplayName("Last Name")]
      public string LastName { get; set; }
  
      [DisplayName("Date Submitted")]
      public DateTime GetDate { get; set; }
  
      public int AdministratorId{ get; set; }
  
      public virtual Administrator Administrator{ get; set; }
  }
  </code></pre>
  
  <p>Controller (Index):</p>
  
  <pre><code> public ActionResult Index()
      {
          ViewBag.LoanOfficerId = new SelectList(db.Administrators, "AdministratorId", "AdministratorName");
          return View();
      }
  
      // POST: Applications/Create
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Index([Bind(Include = "AdministratorId,FirstName,MiddleInitial,LastName,")] Application application)
      {
  
  
  
          if (ModelState.IsValid)
          {
  ViewBag.AdministratorId= new SelectList(db.Administrators, "AdministratorId",     "AdministratorName", application.Administrator);
              db.Applications.Add(application);
              db.SaveChanges();
  
              return RedirectToAction("Thanks");
          }
  
  
          return View(application);
      }
  </code></pre>