nWidart / Laravel-Broadway-Demo

This is a test application using https://github.com/qandidate-labs/broadway
36 stars 3 forks source link

Invalid default value for 'created_at' #9

Open josecelano opened 8 years ago

josecelano commented 8 years ago

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 commented 8 years ago

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.

nWidart commented 8 years ago

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

josecelano commented 8 years ago

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).

m1reta commented 7 years ago

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

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