I'm trying to add a self-referencing FOREIGN KEY CONSTRAINT
on a table (comment):
SET
FOREIGN_KEY_CHECKS = OFF;
ALTER TABLE
`comment` ADD CONSTRAINT comment_parent_id_foreign FOREIGN KEY(parent_id) REFERENCES `comment`(id) ON DELETE CASCADE;
And I get this error:
#1825 - Failed to add the foreign key constraint on table 'comment'. Incorrect options in FOREIGN KEY constraint 'databasename/comment_parent_id_foreign'
Earlier I accidentally added this constraint
on an unintended table (post). I wasn't able to delete the constraint, so I removed the column (parent_id) itself. I created this column again. And now I'm not able to add this self-referencing constraint.
Both have same datatype bigint(20)
(id and parent_id) and commentid
is a primary key
Table is using InnoDB
engine
Here's my table structure:
thanks