我有两张桌子Product
& ProductCategory
。当我在包管理器控制台中执行add-migration
时,一切正常,但是当我运行update-database
时,我收到的错误是无关紧要的:
在表'ProductCategories'上引入FOREIGN KEY约束'FK_ProductCategories_Products_ProductId'可能会导致循环或多个级联路径。指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束。无法创建约束或索引。查看以前的错误
其他人对此问题的不同之处在于我的ProductCategory
表中不包含任何外键。
ProductCategory.cs
public class ProductCategory : DomainModel<int>
{
[Required, StringLength(256)]
public string Name { get; set; }
[MaxLength]
public string Description { get; set; }
[Required]
[DefaultValue(false)]
public bool VisibleToCustomerPublicAccount { get; set; }
[Required]
[DefaultValue(true)]
public bool RequireApproval { get; set; }
public string Thumbnail { get; set; }
[Required]
[DefaultValue(false)]
public bool Inactive { get; set; }
}
Product.cs
[Table("Products")]
public class Product : DomainModel<int>
{
public int ProductCategoryId { get; set; }
[ForeignKey("ProductCategoryId")]
public virtual ProductCategory ProductCategory { get; set; }
[Required, StringLength(256)]
public string Title { get; set; }
[Required, DefaultValue(false)]
public bool AllowEdit { get; set; }
[StringLength(50)]
public string ItemCode { get; set; }
[StringLength(50)]
public string CustomerCode { get; set; }
public int? SupplierId { get; set; }
[ForeignKey("SupplierId")]
public virtual Supplier Supplier { get; set; }
[Column(TypeName = "numeric(5,2)")]
public decimal SalesTaxRate { get; set; }
public int? PressId { get; set; }
[ForeignKey("PressId")]
public virtual Press Press { get; set; }
[MaxLength]
public string Thumbnail { get; set; }
[MaxLength]
public string Description { get; set; }
[MaxLength]
public string Artwork { get; set; }
[MaxLength]
public string Colour { get; set; }
[MaxLength]
public string Delivery { get; set; }
[MaxLength]
public string Material { get; set; }
[MaxLength]
public string Finishing { get; set; }
[MaxLength]
public string Proofs { get; set; }
[MaxLength]
public string Packing { get; set; }
[MaxLength]
public string Notes { get; set; }
[MaxLength]
public string TermsAndInstructions { get; set; }
[StringLength(128)]
public string ShortDescription { get; set; }
[MaxLength]
public string ItemDescription { get; set; }
[MaxLength]
public string PrintReadyFile { get; set; }
[Required, DefaultValue(false)]
public bool VisibleToCustomerPublicAccount { get; set; }
[Required, DefaultValue(false)]
public bool ShowShortDescription { get; set; }
[Required, DefaultValue(false)]
public bool ShowItemDescription { get; set; }
[Required, DefaultValue(false)]
public bool ShowPriceStartFrom { get; set; }
[Required, DefaultValue(false)]
public bool ShowPriceList { get; set; }
[Required, DefaultValue(false)]
public bool ShowPriceSubtotalTax { get; set; }
[Required, DefaultValue(false)]
public bool ShowPrintReadyFile { get; set; }
[Required, DefaultValue(false)]
public bool AllowUserToUploadArtworkFile { get; set; }
public int NumberOfUploadBoxes { get; set; }
[Required, DefaultValue(false)]
public bool MakeFirstFileUploadMandatory { get; set; }
[Required, DefaultValue(false)]
public bool ShowStock { get; set; }
[Required, DefaultValue(false)]
public bool ShowSoldInPacks { get; set; }
[Required, DefaultValue(false)]
public bool AllowGroupRun { get; set; }
[Required, DefaultValue(false)]
public bool ShowCustomerCode { get; set; }
[Required ,DefaultValue(false)]
public bool ShowItemCode { get; set; }
[Required, DefaultValue(false)]
public bool HidePricesOfOptions { get; set; }
[Required, DefaultValue(false)]
public bool QuickAddFunctionEnabled { get; set; }
}
我在这类问题上看到了很多解决方案,但解决方案并不成立,因为ProductCategory
表上没有密钥。