Mysql – How to enable NULL values in MySQL timestamp fields

backupmariadbMySQL

I need to restore backup from one MariaDB server (version 10.1.23) to another MariaDB server (version 10.1.37). But this version has a much stricter mode by default and does not allow NULL values in timestamp fields and throws the below error when I restore the backup.

1067 – Invalid default value for 'dt'

I try to add this values to *.cnf file in /etc/mysql/conf.d/

[mysqld]

sql_mode=ALLOW_INVALID_DATES,IGNORE_SPACE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
explicit_defaults_for_timestamp=OFF

Queries:

show variables like 'sql_mode';
show variables like 'explicit_defaults_for_timestamp';

show changed values of variables but it does not work. Why?

Best Answer

ALTER TABLE table_name 
  MODIFY dt TIMESTAMP NULL;

This will alter the table with name table_name to set the column dt to nullable.