首页 文章

播种时出现sql错误指定的密钥对于电子邮件来说太长了

提问于
浏览
0

嗨,我刚开始laravel的一个新项目,所以这是最新版本5.4,我在为单个用户播种到数据库时遇到错误,我收到此错误

[Illuminate \ Database \ QueryException] SQLSTATE [42000]:语法错误或访问冲突:1071指定密钥长;最大密钥长度为1000字节(SQL:alter table users add unique users_email_uniqueemail ))

[PDOException] SQLSTATE [42000]:语法错误或访问冲突:1071指定密钥长;最大密钥长度为1000字节

User::create([
    'name' => 'someone'
    'email' => 'someone@outlook.com',
    'password' => bcrypt('mypassword'), 
]);


<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

1 回答

  • 0

    你应该尝试这样:

    use  Illuminate\Support\Facades\Schema; // At the top of your file
    

    并在AppServiceProvider的boot()方法中添加以下行:

    Schema::defaultStringLength(191);
    

    希望这对你有用!!!

相关问题