我正在爲我的網站創建一個「民意調查」插件,爲此我有兩張表格(如下所示)。外鍵已接受但無法正常工作
我想要實現的是,通過從dd_polls
表中刪除「輪詢」,dd_poll_options
表中的任何鏈接外鍵也被刪除。
這兩個表格創建得很好,但是我的期望如上所述沒有發生。
我正在以正確的方式使用foreign keys
,如果是的話,我的代碼如何修復?謝謝。
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)
)
'CONSTRAINT'是可選的,但我同意其餘的,可能是MyISAM。 –
這兩個表的類型確實是'MyISAM'。我會尋找一種將它們創建爲InnoDB的方法,然後重試。謝謝。 –
@David:也看看我在我的回答中發佈的鏈接。有一種簡單的方法可以實時將存儲引擎切換到InnoDB的每個表:ALTER TABLE xxxx ENGINE = InnoDB; – mwhs