laravel5.4 迁移数据库 出错(二)

来源:互联网 发布:淘宝哪个利润高 编辑:程序博客网 时间:2024/06/05 18:07

代码如下

public function up()    {        Schema::create('password_resets', function (Blueprint $table) {            $table->string('email')->index();            $table->string('token');            $table->timestamp('created_at')->nullable();        });    }

错误信息如下

  [Illuminate\Database\QueryException]  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_name_unique`(`name`))  [PDOException]  SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

解决方法如下

在AppServiceProvider.php中添加

use Illuminate\Support\Facades\Schema;public function boot(){    Schema::defaultStringLength(191);}

参考资料:

https://laravel-news.com/laravel-5-4-key-too-long-error

原创粉丝点击