1

I cannot make it work. An example from http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

CREATE TABLE parent (id INT NOT NULL,
                     PRIMARY KEY (id)
) ENGINE=INNODB;

CREATE TABLE child (id INT, parent_id INT,
                    INDEX par_ind (parent_id),
                    FOREIGN KEY (parent_id) REFERENCES parent(id)
                     ON DELETE CASCADE
) ENGINE=INNODB;

What am I doing wrong?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
alvizouri
  • 83
  • 2
  • 7

1 Answers1

1

When creating the child table your reference has to be a constraint

CONSTRAINT FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE

If that fails, use the following query to check if your configuration checks for references

SHOW VARIABLES LIKE 'foreign_key_checks'
transistor09
  • 4,828
  • 2
  • 25
  • 33