MySQL modified the "Default" and "Extra" value for timestamp fields

400 Views Asked by At

I'm using Laravel migrations to create users table. It has created_at and updated_at fields which have been created using $table->timestamps();

The resulting table structure looks like this;

enter image description here

Why do both of the timestamp fields have a default value? As far as I'm concerned Laravel migrations $table->timestamps(); doesn't set the default value for timestamp.

Also, the created_at field's "Extra" has been set to on update CURRENT_TIMESTAMP. I don't think Laravel migrations set this either.

Does anyone know why MySQL behave this way? I'm using MySQL 5.7.10 by the way.

UPDATE: As of Laravel v5.2.24 timestamps have been made nullable by default, so this won't be a problem anymore - commit

1

There are 1 best solutions below

0
Wader On BEST ANSWER

This is related to differences between MySQL versions and strict mode, specifically <= 5.6 and 5.7 as strict mode is now enabled by default. See https://github.com/laravel/framework/issues/11518

The solution for now seems to be either use $table->nullableTimestamps() or manually defining both created_at and updated_at columns as below

$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();