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

前端 未结 14 1720
-上瘾入骨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:16

    Try and run the following command:

    ALTER TABLE `investments` 
    MODIFY created_at TIMESTAMP 
    DEFAULT CURRENT_TIMESTAMP 
    NOT NULL;
    

    and

    ALTER TABLE `investments` 
    MODIFY updated_at TIMESTAMP 
    DEFAULT CURRENT_TIMESTAMP 
    NOT NULL;
    

    The reason you are getting this error is because you are not setting a default value for the created_at and updated_at fields. MySQL is not accepting your command since the values for these columns cannot be null.

    Hope this helps.

提交回复
热议问题