Title: Database Error: Column &#8216;mail_id&#8217; cannot be null
Last modified: January 10, 2019

---

# Database Error: Column ‘mail_id’ cannot be null

 *  Resolved [Rafael](https://wordpress.org/support/users/jordh/)
 * (@jordh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/)
 * Hello,
 * two days ago, _WP Mail Logging_ stopped logging any new Mail sent by our website.
   I did some testing and got these messages in my debug.log file:
 * `WordPress Database Error Column 'mail_id' cannot be null for query INSERT INTO'
   wp_wpml_mails ('mail_id', 'timestamp', 'host', 'receiver', 'subject','message','
   headers', 'attachments', 'error', 'plugin_version') VALUES (NULL, '2019-01-10
   13:50:03', [...]`
 * It appears that the value for ‘mail_id’ gets lost somewhere before attempting
   to insert the logged mail into the database.
 * On our staging environment, I have tried switching to default themes (Twenty 
   Nineteen and Twenty Fifteen) and deactivating all plugins except for _WP Mail
   Logging_, _WP Mail SMTP_ and _Check Email_ (to generate test mails). The issue
   persists.
 * The only thing that changed around the time as the logging stopped was that I
   updates _WPML_ (Worpress Multilingual) to its latest version, but the error occurs
   even when _WPML_ is deactivated.
 * The site runs on WordPress 5.0.3 (5.0.2 at the time logging stopped working) 
   and the latest version of all plugins mentioned above.
 * Regards,
    Rafael
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).
      Reason: Formatting
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).
      Reason: Formatting again, the ` symbol within the code messes it all up
    -  This topic was modified 7 years, 5 months ago by [Rafael](https://wordpress.org/support/users/jordh/).

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

 *  [No3x](https://wordpress.org/support/users/no3x/)
 * (@no3x)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11073420)
 * Hi [@jordh](https://wordpress.org/support/users/jordh/),
 * > It appears that the value for ‘mail_id’ gets lost somewhere before attempting
   > to insert the logged mail into the database.
 * NULL ist ok for the insert – it tells the RDBMS to figure out an id. In the case
   of the plugin it’s an autoincrement integer.
    So that’s not the issue for a “
   stable” installation of the plugin. Did you use a DB migration tool? I think 
   the database schema changed somehow and introduced the issue by accident.
 * I use WPML(WP Mail Logging) here and there as abbreviation – obiously there is
   a clash with Worpress Multilingual. But I’m not aware of any issues with it yet.
    -  This reply was modified 7 years, 5 months ago by [No3x](https://wordpress.org/support/users/no3x/).
    -  This reply was modified 7 years, 5 months ago by [No3x](https://wordpress.org/support/users/no3x/).
 *  Thread Starter [Rafael](https://wordpress.org/support/users/jordh/)
 * (@jordh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11073515)
 * I took a look at the `wp_wpml_mails` table in phpMyAdmin. The `mail_id` column
   has the type `int(11)`. Is that correct?
 * By the way, the last value for `mail_id` has been `4727` and was entered around
   two days ago.
 * While I did a database migration when I mirrored the site to our staging environment
   yesterday, I did so by hand (exporting an .sql file, deleting all existing tables
   in the staging database and importing the previously exported file). The error
   however occurs on both versions of the site (I generated the above mentioned 
   error log on the live site).
 * We’ve been using WP Mail Logging alongside WordPress Multilingual since December
   2017; there haven’t been any compatibility issues so far.
 *  [No3x](https://wordpress.org/support/users/no3x/)
 * (@no3x)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11073563)
 * A normal INSERT looks like:
 *     ```
       INSERT INTO 'wp_wpml_mails'('mail_id','timestamp','host','receiver','subject','message','headers','attachments','error','plugin_version')
       VALUES (NULL, '2019-01-10 14:39:05', '172.17.0.32', 'B@B.B', 'Subject', 'Content', 'From: \"B\" <B@B.B>\r\n', '', NULL, '1.8.5')
       ```
   
 * So it’s pretty much the same as yours. This tells us that the error must be in
   the database scheme.
 * `int(11)` – `INT` is okay, 11 limits the number of digits when viewing the data
   via cli (very unimportant for the issue). The max ID is 2147483647.
    The column
   is created during the installation as: `'mail_id' INT NOT NULL AUTO_INCREMENT`.
   You should be able to verify this in phpmyadmin.
    -  This reply was modified 7 years, 5 months ago by [No3x](https://wordpress.org/support/users/no3x/).
 *  Thread Starter [Rafael](https://wordpress.org/support/users/jordh/)
 * (@jordh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11073682)
 * I am attempting to manually add the Auto_Increment attribute to the column, it
   looks good when I press SQL preview:
 * `ALTER TABLE 'wp_wpml_mails' CHANGE 'mail_id' 'mail_id' INT(11) NOT NULL AUTO_INCREMENT;`
 * But when I try to save the changes, I get the following error:
 * `#1075 - Incorrect table definition; there can be only one auto column and it
   must be defined as a key`
 * No other column has the Auto_Increment attribute. So do I have to set the mail_id
   column as a key as well? And where do I do that?
 * Sorry to ask all these questions, I am a beginner at best when it comes to databases…
 *  Thread Starter [Rafael](https://wordpress.org/support/users/jordh/)
 * (@jordh)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11076798)
 * I managed to manually fix the table by adding an index to `mail_id` first:
 * `ALTER TABLE 'wp_wpml_mails' ADD INDEX('mail_id');`
 * Then I was able to add the `Auto_Increment` attribute:
 * `ALTER TABLE 'wp_wpml_mails' CHANGE 'mail_id' 'mail_id' INT(11) NOT NULL AUTO_INCREMENT;`
 * Now the table accepts the requests again and new mails are properly logged.
 * Thank you for pointing me in the right direction!
 * Regards,
    Rafael

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

The topic ‘Database Error: Column ‘mail_id’ cannot be null’ is closed to new replies.

 * ![](https://ps.w.org/wp-mail-logging/assets/icon-256x256.jpg?rev=2562296)
 * [WP Mail Logging](https://wordpress.org/plugins/wp-mail-logging/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-mail-logging/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-mail-logging/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-mail-logging/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-mail-logging/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-mail-logging/reviews/)

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [NULL](https://wordpress.org/support/topic-tag/null/)

 * 5 replies
 * 2 participants
 * Last reply from: [Rafael](https://wordpress.org/support/users/jordh/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/database-error-column-mail_id-cannot-be-null/#post-11076798)
 * Status: resolved