cycles or multiple cascade paths in ef core RRS feed

  • Question

  • User338455301 posted


    i have this error in update database , whats problem ?


            public int ProductInfo_ID { get; set; }
            public virtual IEnumerable<SimilarProduct> SimilarProduct { get; set; }
            public virtual IEnumerable<SimilarProduct> SimilarProduct2 { get; set; }


            public int ID { get; set; }
            public int ProductInfo_ID { get; set; }
            public ProductInfo ProductInfo { get; set; }
            public int ProductSimilarID { get; set; }
            public ProductInfo SimilarProduct1 { get; set; }

    Introducing FOREIGN KEY constraint 'FK_SimilarProduct_tb_ProductInfo_tb_ProductSimilarID' on table 'SimilarProduct_tb' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
    Could not create constraint or index. See previous errors.

    i set this but its not worked 

              builder.Entity<SimilarProduct>()       // THIS IS FIRST
    .HasOne(u => u.ProductInfo).WithMany(u => u.SimilarProduct).IsRequired().OnDelete(DeleteBehavior.Restrict);
           .HasOne(pt => pt.SimilarProduct1)
           .WithMany(p => p.SimilarProduct2)
           .HasForeignKey(pt => pt.ProductSimilarID).OnDelete(DeleteBehavior.Restrict); 

    Monday, April 13, 2020 11:41 AM

All replies

  • User-854763662 posted

    Hi elahi1mahdi ,

    Are you saying that the error occurred when using the update-database command?

    I tested your code , but there is no error and it updated the database successfully in migration.

    Did you try the solution suggested in the error ? What's your generated migration file and the complete DbContext? 

    Best Regards,


    Tuesday, April 14, 2020 6:24 AM
  • User-217098811 posted

    Hi elahi1mahdi

    You have encountered an error while updating the database because you did not remove the previous error migration

    Try entering in the package manager console


    Remember to delete all migrations

    I had the same problem as you and I solved it in this way

    Best Regards


    Tuesday, June 2, 2020 6:39 AM