I have the following sql create statement
mysql> CREATE TABLE IF NOT EXISTS `erp`.`je_menus` (
-> `id` INT(11) NOT NULL AUTO_INCREMENT ,
-&g
Using OS X, install mysql from Homebrew, System Variables based on its compiled-in defaults. Solution is to remove "NO_ZERO_DATE" from System Variables "sql_mode".
Just please keep in mind that scope involve.
If you want to affect only in your session, please use "@@session"
, For example:
SET @@session.sql_mode ="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION".
In this case, it will not affect once your session ends or your change it. It has not effect on other session.
If you want to affect on all client, please use "@@global"
, for example:
SET @@global.sql_mode ="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION".
In this case, it only affects on the clients that connect after the change(not affect on current all clients), and will not work once server exit.
You could just change this:
`create_date` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
To something like this:
`create_date` TIMESTAMP NOT NULL DEFAULT '2018-04-01 12:00:00',
That is because of server SQL Mode - NO_ZERO_DATE.
From the reference: NO_ZERO_DATE
- In strict mode, don't allow '0000-00-00'
as a valid date. You can still insert zero dates with the IGNORE option. When not in strict mode, the date is accepted but a warning is generated.
In ubuntu desktop 16.04, I did this:
open file: /etc/mysql/mysql.conf.d/mysqld.cnf
in an editor of your choice.
Look for: sql_mode
, it will be somewhere under [mysqld]
.
and set sql_mode
to the following:
NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Save and then restart mysql service by doing:
sudo service mysql restart
I had a similar issue with MySQL 5.7 with the following code:
`update_date` TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
I fixed by using this instead:
`update_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
Default values should start from the year 1000.
For example,
ALTER TABLE mytable last_active DATETIME DEFAULT '1000-01-01 00:00:00'
Hope this helps someone.