ERROR 1067 (42000): Invalid default value for 'created_at'

前端 未结 14 1673
-上瘾入骨i
-上瘾入骨i 2020-12-04 07:31

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

相关标签:
14条回答
  • 2020-12-04 08:19

    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 = '';

    0 讨论(0)
  • 2020-12-04 08:20

    Simply, before you run any statements put this in the first line:

    SET sql_mode = '';
    
    0 讨论(0)
  • 2020-12-04 08:20

    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.

    0 讨论(0)
  • 2020-12-04 08:20

    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!

    0 讨论(0)
  • 2020-12-04 08:21

    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!

    0 讨论(0)
  • 2020-12-04 08:23

    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

    0 讨论(0)
提交回复
热议问题