Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The DELETE statement conflicted with the REFERENCE constraint "FK_Cart_Product".The conflict occurred in database "FinalProject", table "dbo.Cart", column 'ProductID'.
The statement has been terminated.

What I have tried:

Is this because of not allowing nullable to column PRoductId
Posted
Updated 24-Mar-18 6:06am

1 solution

It's difficult to give an exact answer without seeing your actual delete statement and the exact error message, however...

A foreign key constraint violation is thrown when you try to delete a parent record for which there are children rows in a related table.

So you need to delete the child rows first.

For example deleting a product from the product table would be a problem if that product was present in the orders table.

So in the case I illustrate above you would need to first delete every order line containing that product then delete the product from the product table.
Which you probably would not want to do as you would be deleting history related to the product.

So the question is - are you sure you really want to delete that record as the foreign key constraint is there for a very good reason?

If you are sure you want to delete the row you will first need to delete every occurrence of the ProductID in all the table bound by the foreign key constraint.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900