I am using wordpress 4.9.6
with mysqlnd 5.0.12-dev
as db. I have created my own tables which uses post_id as a Foreign Key Constraint.
When I want to delete a post in my backend I get:
WordPress database error: [Cannot delete or update a parent row: a foreign key constraint fails (`my_own_database`.`wp_product`, CONSTRAINT `wp_product_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `wp_posts` (`ID`))]
DELETE FROM `wp_posts` WHERE `ID` = 300
Error in deleting.
The table I am referencing the post_id to looks like the following:
CREATE TABLE wp_product(
id BIGINT(20) NOT NULL AUTO_INCREMENT,
post_id BIGINT(20) UNSIGNED,
product_id BIGINT(20) NOT NULL,
daily_netProfit DECIMAL(30,15) NOT NULL,
daily_grossProfit DECIMAL(30,15) NOT NULL,
daily_costs DECIMAL(30,15) NOT NULL,
created_at DATETIME NULL,
updated_at DATETIME NULL,
PRIMARY KEY (id),
FOREIGN KEY (post_id) REFERENCES wp_posts(ID),
FOREIGN KEY (product_id) REFERENCES {$wpdb->prefix}products(id)
);
Any suggestions how to delete the post, when pressing the delete button in my backend?
I appreciate your replies!