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

前端 未结 14 1674
-上瘾入骨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:30
    1. First, check existing mode(s) are using the following command in your terminal:

      $ mysql -u root -p -e "SHOW VARIABLES LIKE 'sql_mode';"

      or

      mysql> show variables like 'sql_mode';

      You would see an output like below

    2. Disable mode(s) via my.cnf: In this case, you need to remove NO_ZERO_IN_DATE, NO_ZERO_DATE modes

      Open my.cnf file (Generally you could find my.cnf file located in /etc/my.cnf or /etc/mysql/my.cnf)

      Update modes in my.cnf under [mysqld] heading

      sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

      Here I have omitted NO_ZERO_IN_DATE, NO_ZERO_DATE modes

    3. Restart mysql server

      $ /etc/init.d/mysql restart

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

    Resolved my problem.

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