这个问题在这里已有答案:
我正在尝试迁移laravel迁移但我有一个错误:
Migrating: 2014_10_12_100000_create_password_resets_table
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 `password_
resets` add index `password_resets_email_index`(`email`))
我的代码是:
if (!Schema::hasTable('password_resets')) {
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
你可以通过放置它来手动设置字符串长度
$table->string('name', 191); // You can put any number in exchange of 191
其他
把它放在APP - > Providers - > AppServiceProvider中
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
您应该在AppServiceProvider的引导方法中将默认字符串长度设置为191
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}