When I tried to alter the table it showed the error:
ERROR 1067 (42000): Invalid default value for \'created_at\'
I googled for this error
I came across the same error while trying to install a third party database.
I tried the solution proposed unsuccessfully i.e.
SET sql_mode = '';
Then I tried the command below which worked allowing the database to be installed
SET GLOBAL sql_mode = '';
Simply, before you run any statements put this in the first line:
SET sql_mode = '';
I had similar problem. Following solved it:
Change:
recollect_date TIMESTAMP DEFAULT 'CURRENT_TIMESTAMP',
to:
recollect_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
i.e. just remove the quotes around CURRENT_TIMESTAMP.
Hope this helps someone.
For Mysql5.7, login in mysql command line and run the command,
mysql> show variables like 'sql_mode' ;
It will show that NO_ZERO_IN_DATE,NO_ZERO_DATE in sql_mode.
Try to add a line below [mysqld] in your mysql conf file to remove the two option, mine(mysql 5.7 on Ubuntu 16) is /etc/mysql/mysql.conf.d/mysqld.cnf
Now restart mysql. It works!
In my case I have a file to import. So I simply added SET sql_mode = ''; at the beginning of the file and it works!
Just convert it by this line :
for the new table :
CREATE TABLE t1 (
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
for Existing Table:
Alter ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
Source :
https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html