php – 语法错误或访问冲突:1067“created_at”的默认值无效

我安装laravel 5.5并且当我运行PHP artisan migrate时显示我的错误

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

我在AppServiceProvider.PHP添加了以下代码

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

然后告诉我这个错误

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

解决方法

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

要么

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

请查看以下参考链接

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...