I tried creating the tables in different ways and I always get the same error: "Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '( ...... at line 1 of the WordPress database for the CREATE TABLE IF NOT query EXISTS"
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
global $wpdb, $rs_plugin_db_version, $table_name_clientes, $table_name_promociones;
$charset_collate = $wpdb->get_charset_collate();
$wpdb->query(
"CREATE TABLE IF NOT EXISTS $table_name_clientes (
id int(11) NOT NULL,
logo text NOT NULL,
name text NOT NULL,
whatsapp text DEFAULT '' NOT NULL,
instagram text DEFAULT '' NOT NULL,
facebook text DEFAULT '' NOT NULL,
PRIMARY KEY (id)
) $charset_collate ENGINE = InnoDB"
);
dbDelta();
$wpdb->query(
"CREATE TABLE IF NOT EXISTS $table_name_promociones (
id int(11) NOT NULL,
img text NOT NULL,
title text NOT NULL,
content text NOT NULL,
owner int(11) NOT NULL,
contact int(11) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (owner) REFERENCES $table_name_clientes(id) ON DELETE CASCADE ON UPDATE CASCADE
) $charset_collate ENGINE = InnoDB"
);
dbDelta();
In one of the tables I need to create a foreign key, if I didn't misunderstood dbDelta() does not support them and therefore my last attempt was with $wpdb->query, but with or without foreign key the result is the same.
maybe my mistake is obvious, but honestly I can't find it
dbDelta
works or what the examples look like.dbDelta
takes a create table sql statement as a parameter, you shouldn't be making queries withwpdb