EF Core failed to execute database update command : " fail: Microsoft.EntityFrameworkCore.Database.Command[20102] "

Solution 1:

Introducing FOREIGN KEY constraint 'FK_ProductSubCategory_SubCategory_SubCategoryId' on table 'ProductSubCategory' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

The error is literally telling you the problem here. I am not sure what bit is unclear, as the OP states they understand none of it (which I must admit implies a language barrier and so I suggest changing the language of your LOGIN to get the error in a language you are more familiar with), however, I'm going to overly "dumb" this down:

Introducing FOREIGN KEY constraint 'FK_ProductSubCategory_SubCategory_SubCategoryId'

This is talking about the FOREIGN KEY you are trying to create called FK_ProductSubCategory_SubCategory_SubCategoryId

on table 'ProductSubCategory'

This is telling you that the aforementioned FOREIGN KEY is trying to be created on the table ProductSubCategory

may cause cycles or multiple cascade paths.

This means that the aforementioned FOREIGN KEY, that is trying to be created on the aforementioned TABLE, will cause cycles or multiple cascade paths.

  • A Cycle would mean that the DELETE will cause further deletes on the same table, trigging more deletes on the same table, trigging more deletes on the same table, ... trigging more deletes on the same table, ... (You get the idea)
  • Multiple Cascade Paths means that there will be multiple other tables that will have rows deleted from, which is now allowed in SQL Server; especially if they converge on the same table later on.

Specify ON DELETE NO ACTION or ON UPDATE NO ACTION

I don't really know how to clarify this further. Instead of ON CASCADE use NO ACTION. AKA, handle the cascading yourself.

or modify other FOREIGN KEY constraints

Again, this is very much telling you what to do. Modify the other CONSTRAINTs on your table so that they won't cause a cycle or multiple paths; must likely by changing that key to NO ACTION and handing the cascading yourself.

Solution 2:

Try to change

 modelBuilder.Entity<ProductSubCategory>()
                .HasOne(psc => psc.Product)
                .WithMany(p => p.SubCategories)
                .HasForeignKey(psc => psc.ProductId);

To

 modelBuilder.Entity<ProductSubCategory>()
                .HasOne(psc => psc.Product)
                .WithMany(p => p.ProductSubCategories)
                .HasForeignKey(psc => psc.ProductId);

And I usually use .OnDelete(DeleteBehavior.ClientSetNull)