语法错误或访问冲突:1067"created_at"的默认值无效

par*_*oid 3 php mysql laravel laravel-5

我安装了laravel 5.5,当我运行时php artisan migrate告诉我这个错误

[Illuminate\Database\QueryException] SQLSTATE [42000]:语法错误或访问冲突:1071指定密钥太长; 最大密钥长度为767字节(SQ L:alter table usersadd unique users_email_unique(email))

我在下面添加了代码 AppServiceProvider.php

 public function boot()
{
     Schema::defaultStringLength(191); //Solved by increasing StringLength
}
Run Code Online (Sandbox Code Playgroud)

然后告诉我这个错误

[Illuminate\Database\QueryException] SQLSTATE [42000]:语法错误或访问冲突:1067"created_at"的默认值无效(SQL:create table password_resets(emailvarchar(191)not null,tokenvarchar(191)not null,created_attimestamp not null) de fault字符集utf8mb4 collat​​e utf8mb4_unicode_ci)

Api*_*ail 8

我目前正在使用 Laravel 7。

我只是去 config/database.php

然后我更改strict => truestrict => false.

然后再次运行相同的迁移。有用。


Jig*_*hah 7

你可以用nullableTimestamps()而不是timestamps()

要么

$table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
Run Code Online (Sandbox Code Playgroud)

请查看以下参考链接:

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


sab*_*zdi 7

我的情况

        $table->timestamp('deleted_at')->nullable()->default(null);
Run Code Online (Sandbox Code Playgroud)

这有效