Wordpress create database with FOREIGN KEY
<p>I am trying to create a wordpress plugin that will use two databases I need them to have FOREIGN KEY but cannot get the plugin to create them only if I remove the FOREIGN KEY can I get them to create a table.</p>

<pre><code>global $wpdb;
  $table_name = $wpdb-&gt;prefix . 'aa_accessform';
  $table_name2 = $wpdb-&gt;prefix . 'aa_formcomments';

  $charset_collate = $wpdb-&gt;get_charset_collate();

    $wpdb-&gt;query(
        "CREATE TABLE IF NOT EXISTS $table_name (
            id              INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
            customer_id     INT UNSIGNED NOT NULL,
            appointment_id  INT UNSIGNED NOT NULL,
            notes TEXT,
            token VARCHAR(255) DEFAULT NULL
        ) ENGINE = INNODB
        DEFAULT CHARACTER SET = utf8
        COLLATE = utf8_general_ci"
    );
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
    $wpdb-&gt;query(
        "CREATE TABLE IF NOT EXISTS $table_name2 (
            id              INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
            customer_codes__id     INT UNSIGNED NOT NULL,
            appointment_codes_id  INT UNSIGNED NOT NULL,
            notes TEXT,
            token VARCHAR(255) DEFAULT NULL,
            PRIMARY KEY  (id),
            FOREIGN KEY  (customer_codes__id) REFERENCES ".$table_name." (id)
        ) ENGINE = INNODB
        DEFAULT CHARACTER SET = utf8
        COLLATE = utf8_general_ci"
    );
    dbDelta( $sql );
</code></pre>

<p>I would love to know what is wrong.</p>