I am using SQLite with EFCore. I am trying to save several items that are part of the same category, but when I try to save them I am getting a foreign key constraint error.
The Error: "SQLite Error 19: 'FOREIGN KEY constraint failed'."
The models look like this:
public class Item
{
public int ItemId { get; set; }
public string ItemName {get; set; }
[ForeignKey("CategoryId")]
public int CategoryId { get; set; }
}
public class Category
{
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public List<Item>? Items { get; set; }
}
So a category can have a lot of items and many of them will each have the same category ID as a foreign key. Is this possible with SQLite?