Voyager: Incorrect datetime value: '1970-01-01 00:00:00' for column 'created_at'

Created on 10 Jan 2017  路  2Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.3.29
  • Voyager Version: 0.10.8
  • PHP Version: 7.0.3
  • Database Driver & Version: MySQL 5.6.25

Description:

I kept getting this error, when trying to edit a user profile:
Incorrect datetime value: '1970-01-01 00:00:00' for column 'created_at'

Tried lots of things.

Like changing all migration files in vendortcgvoyagerpublishabledatabasemigrations
This:
$table->timestamps();
into:
$table->nullableTimestamps('updated_at')->useCurrent();
$table->nullableTimestamps('created_at')->useCurrent();

And experiments with CURRENT_TIMESTAMP...

But nothing worked.
So eventually I hacked this file:
vendortcgvoyagersrcHttpControllersController.php

I added this:

if ($content == '1970-01-01 00:00:00') $content = null;

to

`/** TIMESTAMP TYPE **/
case 'timestamp':
if ($request->isMethod('PUT')) {

    $content = gmdate('Y-m-d H:i:s', strtotime($request->input($row->field)));

    //-------------------------------------------------------------
    // $content: '1970-01-01 00:00:00' can break update queries:
    //     SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1970-01-01 00:00:00' for column 'created_at' 
    // Setting to null instead avoids this problem:

    if ($content == '1970-01-01 00:00:00')  $content = null;

    //-------------------------------------------------------------
}
break;

`
Eh voil谩 - no more problems. :-)

But of course this is a very ugly and primitive hack....
If anyone has a more elegant solution, let me know?

Most helpful comment

Please update your users BREAD to prevent updating created_at column like so:

image

All 2 comments

Please update your users BREAD to prevent updating created_at column like so:

image

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

winex01 picture winex01  路  3Comments

wp-src picture wp-src  路  3Comments

ferrywae picture ferrywae  路  4Comments

raoasifraza1 picture raoasifraza1  路  3Comments

zzpwestlife picture zzpwestlife  路  3Comments