My Shop and Product entities have a one to many relationship, please see my models
public class Product
{
public int ID { get; set; }
public string Name {
Declare ShopID as nullable in the Product table, you are doing product.Shop = null;, so it tries to insert ShopID value null in this column. Since you column ShopID in Product table is not nullable, that is why its giving error. Because there is no Id in Shop table which is nullable. So its giving foreign key constraint fails exception. So all you have to do is to make use the nullable foreign key like public int? ShopID.