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 uniqueusers_email_unique(
我在下面添加了代码 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(tokenvarchar(191)not null,created_attimestamp not null) de fault字符集utf8mb4 collate utf8mb4_unicode_ci)
我目前正在使用 Laravel 7。
我只是去 config/database.php
然后我更改strict => true为strict => false.
然后再次运行相同的迁移。有用。
你可以用nullableTimestamps()而不是timestamps()
要么
$table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
Run Code Online (Sandbox Code Playgroud)
请查看以下参考链接:
https://github.com/laravel/framework/issues/3602
我的情况
$table->timestamp('deleted_at')->nullable()->default(null);
Run Code Online (Sandbox Code Playgroud)
这有效
| 归档时间: |
|
| 查看次数: |
5808 次 |
| 最近记录: |