Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I install laravel 5.5 and When I run php artisan migrate show me this error

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQ L: alter table users add unique users_email_unique(email))

And I add below code on AppServiceProvider.php

 public function boot()
{
     Schema::defaultStringLength(191); //Solved by increasing StringLength
}

And then show me this error

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: create table password_resets (email varchar(191) not null, token varchar(191) not null, created_at timestamp not null) de fault character set utf8mb4 collate utf8mb4_unicode_ci)

like image 337
paranoid Avatar asked Aug 29 '17 09:08

paranoid


3 Answers

I'm currently using laravel 7.

I just go to config/database.php

Then I change strict => true to strict => false.

Then run the same migration again. It works.

like image 105
Apit John Ismail Avatar answered Nov 17 '22 12:11

Apit John Ismail


my case

        $table->timestamp('deleted_at')->nullable()->default(null);

this worked

like image 31
saber tabatabaee yazdi Avatar answered Nov 17 '22 12:11

saber tabatabaee yazdi


You can use nullableTimestamps() instead of timestamps()

or

$table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));

also check the database server version

Please have a look on these ref links:

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

https://laracasts.com/discuss/channels/forge/syntax-error-or-access-violation-1067-invalid-default-value-for-created-at

like image 20
Jigar Shah Avatar answered Nov 17 '22 13:11

Jigar Shah