Pada PHP 5.3.13 / MySQL 5.5.21 kode berikut tidak berfungsi:
if($check_custom_fields_form!=1){
$sql = "CREATE TABLE IF NOT EXISTS ". $table_custom_fields_form ." (
`form_name` longtext NOT NULL,
`field_id` bigint(20) NOT NULL,
FOREIGN KEY (`field_id`) REFERENCES $table_custom_fields (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) CHARACTER SET utf8 COLLATE utf8_general_ci";
dbDelta($sql);
}
if($check_subscribe_cat!=1){
$sql = "CREATE TABLE IF NOT EXISTS ". $table_subscribe_cat ." (
`subscribe_id` bigint(20) NOT NULL,
`cat_id` bigint(20) NOT NULL,
FOREIGN KEY (`subscribe_id`) REFERENCES ".$wpdb->prefix."tgt_subscription (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`cat_id`) REFERENCES ".$wpdb->prefix."terms (`term_id`) ON DELETE CASCADE ON UPDATE CASCADE
) CHARACTER SET utf8 COLLATE utf8_general_ci";
dbDelta($sql);
}
The penyedia kode disarankan downgrade ke MySQL 5.1.37 (tidak, terima kasih) atau pembaruan berikut:
if($check_custom_fields_form!=1){
$sql = "CREATE TABLE IF NOT EXISTS ". $table_custom_fields_form ." (
`form_name` longtext NOT NULL,
`field_id` bigint(20) NOT NULL,
KEY(field_id)
) CHARACTER SET utf8 COLLATE utf8_general_ci";
dbDelta($sql);
}
if($check_subscribe_cat!=1){
$sql = "CREATE TABLE IF NOT EXISTS ". $table_subscribe_cat ." (
`subscribe_id` bigint(20) NOT NULL,
`cat_id` bigint(20) NOT NULL,
KEY(subscribe_id),
KEY(cat_id)
) CHARACTER SET utf8 COLLATE utf8_general_ci";
dbDelta($sql);
}
Yang sepertinya cara yang agak kotor untuk mengatasi masalah (tidak ada penghapusan / pembaruan cascading). Karena itu:
- Apakah saya benar-benar harus hidup dengan itu sampai dbDelta mendukung KUNCI ASING ?
- Benarkah dbDelta hanya berfungsi dengan kunci asing dalam versi MySQL berusia 3 tahun?