I have two tables: Message and Product. In the Message table, there is a sourceid, which is equal to ProductId under table Product.
A Product is given a product id (productID), and a user can message the seller regarding the product. And for those messages, if they are related to certain product than they are given a sourceid, which is basically the product id. If the message is not related to any product, the sourceid will be set as 0.
I am able to set a foreign key constrain to delete the message entry whenever a seller delete a product, all related messages will be deleted.
However, I found that all message that is not related to a product, with sourceid set as 0, are not saving in the database. Obviously, because there is not a product with a productid = 0, and that the foreign key constraint will delete the message entry (with sourceid = 0) immediately.
Is there a way to set condition in phpmyadmin? If I can set that if the foreign key constraint only execute when sourceid > 0, then the system should work out. But I am not sure how to set this condition, or if phpmyadmin allow to set this condition.
Please help. Thank you so much.