Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrisgeary92's avatar

Syntax error or access violation: 1067 Invalid default value for 'created_at'

I recently setup a new php7 server with digital ocean, and forge, and envoyer.. When I came to deploy my code it fails during the migrations.

All of the migrations fail to run due to the default value for timestamps. They're set to 0000-00-00 00:00:00 which apparently MySQL doesn't like (assuming due to strict mode).

My migration looks like this:

Schema::create('checks', function (Blueprint $table) {
        $table->increments('id');
        $table->string('hash');
        $table->string('domain')->index();
        $table->string('host')->index();
        $table->timestamps();
        $table->softDeletes();
});

Error is:

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'

I'm running Laravel 5.1, if that makes any difference. How could I go about fixing this?

Also, it works fine within Homestead, and on my old php 5.6 server. It's just the new one which doesn't work :/

0 likes
7 replies
lostdreamer_nl's avatar
Level 53

Some version DB's dont like the usual $table->timestamps() fields Try the $table->nullableTimestamps() they should work.

The difference is that the nullableTimestamps have a default value of NULL ;)

4 likes
Citizen's avatar

We ran into this as well. I don't think the accepted answer is sufficient because right now if you follow Laravel's documentation (at least for 5.1) and spin up a new Laravel Forge server, you get these errors. We run into these errors on the supported stack.

dadaycm's avatar

I fixed this by changing: config/database.php as below:

    'mysql' => [
        'driver'    => 'mysql',
        ...
        'strict'    => true,  // change false  to true
    ],

Wish this helps.

7 likes
maculus1's avatar

@ dadaycm, Thanks alot it works for me too

pzmarzly's avatar

Nowadays Laravel uses nullable timestamps by default, but for your own columns you may want to set a default of now(). It can be done with:

$table->timestamp('start')->useCurrent();

Please or to participate in this conversation.