我正在使用Wordpress和Wordpress数据库。我有3张桌子。两个是包含自己的主键的表,第三个是交叉引用表。问题在于交叉引用或外部参照表。
此外部参照表有两个外键链接到另外两个表的主键。但是,每当我将数据插入前两个表时,外部参照表中都不会显示任何数据。
也许我创建该外部参照表的代码不正确。
$ml_char = $wpdb->prefix . "ml_char";
$charset_collate = $wpdb->get_charset_collate();
$sql1 = "CREATE TABLE IF NOT EXISTS " . $ml_char . " (
`char_id` mediumint(9) NOT NULL AUTO_INCREMENT,
`name` text NOT NULL,
PRIMARY KEY (`char_id`)
) $charset_collate;";
dbDelta( $sql1 );
$ml_wpid = $wpdb->prefix . "ml_wpid";
$charset_collate = $wpdb->get_charset_collate();
$sql2 = "CREATE TABLE IF NOT EXISTS " . $ml_wpid . " (
`wp_id` mediumint(9) NOT NULL,
PRIMARY KEY (`wp_id`)
) $charset_collate;";
dbDelta( $sql2 );
$ml_wpid_x_char = $wpdb->prefix . "ml_wpid_x_char";
$charset_collate = $wpdb->get_charset_collate();
$sql3 = "CREATE TABLE IF NOT EXISTS " . $ml_wpid_x_char . " (
`char_id` mediumint(9) NOT NULL,
`wp_id` mediumint(9) NOT NULL,
FOREIGN KEY (char_id) REFERENCES wp_ml_char(char_id),
FOREIGN KEY (wp_id) REFERENCES wp_ml_wpid(wp_id)
) $charset_collate;";
dbDelta( $sql3 );