Title: Database table missing
Last modified: April 14, 2018

---

# Database table missing

 *  [agrolsy](https://wordpress.org/support/users/agrolsy/)
 * (@agrolsy)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/database-table-missing/)
 * After installing the plugin I get an error message on the woocommerce orders 
   page that the gift coupon database table doesn’t exist?
 * WordPress databasfel: [Table ‘klickerforlaget.s5s8zrr_woocommerce_gift_coupon’
   doesn’t exist]
    SELECT * FROM s5s8zrr_woocommerce_gift_coupon WHERE id_order=
   63412
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdatabase-table-missing%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [agrolsy](https://wordpress.org/support/users/agrolsy/)
 * (@agrolsy)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/database-table-missing/#post-10205185)
 * when I try to create it manually using the sql from the plugin I get the following
   error message
 * CREATE TABLE IF NOT EXISTS wp_woocommerce_gift_coupon(
    id_user BIGINT(20) UNSIGNED
   NOT NULL, id_coupon BIGINT(20) UNSIGNED NOT NULL, id_order BIGINT(20) UNSIGNED
   NOT NULL, KEY woocomerce_key_user_generate_coupons (id_user), KEY woocomerce_key_coupon_generate_coupons(
   id_coupon), KEY woocomerce_key_order_generate_coupons (id_order), FOREIGN KEY(
   id_user) REFERENCES wp_users(ID) ON DELETE CASCADE, FOREIGN KEY (id_coupon) REFERENCES
   wp_posts(ID) ON DELETE CASCADE, FOREIGN KEY (id_order) REFERENCES wp_woocommerce_order_items(
   order_id) ON DELETE CASCADE )CHARACTER SET utf8 COLLATE utf8_general_ci
 * #1005 – Can’t create table `wp_woocommerce_gift_coupon` (errno: 150 “Foreign 
   key constraint is incorrectly formed”)
 *  [rollinsforge](https://wordpress.org/support/users/rollinsforge/)
 * (@rollinsforge)
 * [8 years ago](https://wordpress.org/support/topic/database-table-missing/#post-10322379)
 * Hi agrolsy, I stumbled over this too.
 * problem is there are two bugs in the sql querry:
 * When you open the woocommerce-gift-coupon.php you have to change it like that:
 * $sql = ‘CREATE TABLE IF NOT EXISTS ‘ . $table . ‘(
    id_user BIGINT(20) UNSIGNED
   NOT NULL, id_coupon BIGINT(20) UNSIGNED NOT NULL, id_order BIGINT(20) UNSIGNED
   NOT NULL, KEY woocomerce_key_user_generate_coupons (id_user), KEY woocomerce_key_coupon_generate_coupons(
   id_coupon), KEY woocomerce_key_order_generate_coupons (id_order), FOREIGN KEY(
   id_user) REFERENCES ‘ . $wpdb->base_prefix . ‘users(ID) ON DELETE CASCADE, FOREIGN
   KEY (id_coupon) REFERENCES ‘ . $wpdb->prefix . ‘posts(ID) ON DELETE CASCADE, 
   FOREIGN KEY (id_order) REFERENCES ‘ . $wpdb->prefix . ‘woocommerce_order_items(
   order_id) ON DELETE CASCADE )CHARACTER SET utf8 COLLATE utf8_general_ci’;
 * 1. I changed the way $table is set as otherwise you just create a table named“
   $table”
    2. I changed the database prefix for the user table $wpdb->base_prefix.‘
   users(ID). This is because for multisites there is not extra user table. All 
   use the base-sites user table. Thus the prefix has to link to the base table.
 * Btw: I guess your manual creation did fail bc your wordpress db prefix seems “
   s5s8zrr” but you tried it with: “wp”
 * cheers!
 *  [laudag](https://wordpress.org/support/users/laudag/)
 * (@laudag)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/database-table-missing/#post-10771115)
 * I got the exact same problem since migration from one server to another one.
 * Erreur de la base de données WordPress : [Table ‘AAAAA_AAAAA.ap_woocommerce_gift_coupon’
   doesn’t exist]
    SELECT * FROM ap_woocommerce_gift_coupon WHERE id_order=3568
 * The strange thing is that, I can still reach the old hosting, and no bug : but
   the two database look exactly the same : in the old one, the no ap_woocommerce_gift_coupon
   table, but it works.
 * I tried to put the code of rollinsforge int he php file, but white page appears.
   May be I didn’t undestand what to do with this code. Anyway, it’s working in 
   the other hosting. Why not in the new ?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Database table missing’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/woocommerce-gift-coupon_997c86.svg)
 * [WooCommerce Gift Coupon](https://wordpress.org/plugins/woocommerce-gift-coupon/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-gift-coupon/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-gift-coupon/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-gift-coupon/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-gift-coupon/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-gift-coupon/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [laudag](https://wordpress.org/support/users/laudag/)
 * Last activity: [7 years, 8 months ago](https://wordpress.org/support/topic/database-table-missing/#post-10771115)
 * Status: not resolved