title: EF Core SqlException: Cannot insert explicit value for identity column in table 'MenuCategories' when IDENTITY_INSERT is set to OFF
body: <p>I am trying to save some data into my MenuItems table but I'm prevented by the error </p>
  
  <blockquote>
    <p>SqlException: Cannot insert explicit value for identity column in table 'MenuCategories' when IDENTITY_INSERT is set to OFF</p>
  </blockquote>
  
  <p>I am just trying to set the foreign key using the category id I have, I am not quite sure why I am getting the above error.</p>
  
  <p>This is my <code>MenuItem</code> model:</p>
  
  <pre><code>public class MenuItemViewModel
  {
      [Key]
      [Column("MenuItem_Id")]
      public int MenuItemId { get; set; }
  
      [Required]
      public string Name { get; set; }
  
      [Required]
      public string Description { get; set; }
  
      [Required]
      public decimal Price { get; set; }
  
      [Required]
      [Column("MenuCategory_Id")]
      public MenuCategoryViewModel MenuCategory { get; set; }
  }
  </code></pre>
  
  <p>This is my <code>MenuCategory</code> model:</p>
  
  <pre><code>public class MenuCategoryViewModel
  {
      [Key]
      [Column("MenuCategory_Id")]
      public int MenuCategoryId { get; set; }
  
      [Required]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>I'm trying to assign it the id of an existing category, I do not want it to create a new category.</p>