您好我刚刚开始在laravel中开设一个新项目,因此它是最新版本5.4,我在为单个用户播种数据库时收到错误并且我收到此错误< / p>
[照亮\数据库\ QueryException]
SQLSTATE [42000]:语法错误或访问冲突:1071指定的密钥是t
太久了最大密钥长度为1000字节(SQL:alter table users
添加唯一
users_email_unique
(email
))
[PDOException] SQLSTATE [42000]:语法错误或访问冲突:1071指定的密钥是t 太久了最大密钥长度为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');
}
}
答案 0 :(得分:0)
你应该尝试这样:
use Illuminate\Support\Facades\Schema; // At the top of your file
并在AppServiceProvider的boot()方法中添加此行:
Schema::defaultStringLength(191);
希望这对你有用!!!