微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐