I'm creating a 'polls' plugin for my website, and for this I have 2x tables (shown below).
What I'm trying to achieve is that by delete a 'poll' from the dd_polls
table, any linked foreign keys on the dd_poll_options
table are also deleted.
Both tables create just fine, but my expectation as mentioned above is not happening.
Am I using foreign keys
in the correct way, and if so, how can my code be fixed? Thanks.
CREATE TABLE dd_polls (
ID smallint(3) NOT NULL AUTO_INCREMENT,
poll_created_by smallint(3) DEFAULT "0",
poll_created_date datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
poll_last_edited_by smallint(3) DEFAULT "0",
poll_last_edited_date datetime DEFAULT "0000-00-00 00:00:00" NOT NULL,
poll_title varchar(128) COLLATE latin1_general_ci,
poll_start_date date DEFAULT "0000-00-00" NOT NULL,
poll_expiry_date date DEFAULT "0000-00-00" NOT NULL,
poll_closed tinyint(1) NOT NULL,
poll_allow_recasting tinyint(1) NOT NULL,
poll_show_votes tinyint(1) NOT NULL,
UNIQUE (ID)
)
CREATE TABLE dd_poll_options (
ID smallint(3) NOT NULL AUTO_INCREMENT,
option_text text(255) COLLATE latin1_general_ci,
option_order smallint(2) DEFAULT "0",
poll_id smallint(3) NOT NULL,
FOREIGN KEY (poll_id) REFERENCES dd_polls (ID)
ON DELETE CASCADE,
UNIQUE (ID)
)