Laravel-Broadway-Demo icon indicating copy to clipboard operation
Laravel-Broadway-Demo copied to clipboard

Invalid default value for 'created_at'

Open josecelano opened this issue 9 years ago • 4 comments

When I run php artisan migrate I get this error:

 [Illuminate\Database\QueryException]
  SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: create table `users` (`id` int
   unsigned not null auto_increment primary key, `name` varchar(255) not null, `email` varchar(255) not null, `password` varchar(60)
  not null, `remember_token` varchar(100) null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null)
   default character set utf8 collate utf8_unicode_ci)


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

And it seems to be this one:

https://github.com/laravel/framework/issues/3602

I think my homestead version does not allow to create the table because MySQL config does not allow it.

I have to found out what solution they consider the best.

josecelano avatar Jan 22 '16 13:01 josecelano

I am not sysadmin so I have fixed it quickly and not very well :-) (this should be done in homestead.yml or elsewhere):

Change mysql config file:

...
lc-messages-dir = /usr/share/mysql
sql-mode        = "allow_invalid_dates"
explicit_defaults_for_timestamp
...

Add line sql-mode = "allow_invalid_dates"

sudo vi /etc/mysql/my.cnf
add the line ....
sudo service mysql restart

IMPORTANT: If you run vagrant provision that configuration will be lost.

josecelano avatar Jan 22 '16 15:01 josecelano

There is also this post about removing the mysql strict config: https://mattstauffer.co/blog/how-to-disable-mysql-strict-mode-on-laravel-forge-ubuntu

nWidart avatar Jan 22 '16 17:01 nWidart

OK thanks @nWidart . Maybe you can include this:

In Laravel, you can fix this in code: edit your database.php config file, and add a key of strict with a value of false. But if you're using a non-Laravel application (we've run into this with both CodeIgniter and CraftCMS applications), you won't have that option. Here's how to disable strict mode globally on any Laravel Forge server (and any other Ubuntu server).

in the project config/database.php file, if the project needs it. But I do not know if that could be a problem in others systems where that can not be changed dinamically. I have read somewhere change that config option is a decrepated feature in latest MySQ (but and not sure and I do not know how Laravel does it).

josecelano avatar Jan 22 '16 17:01 josecelano

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

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

m1reta avatar Aug 06 '17 04:08 m1reta