laravel migration指定的密钥太长;最大密钥长度为767字节 [英] laravel migration Specified key was too long; max key length is 767 bytes
本文介绍了laravel migration指定的密钥太长;最大密钥长度为767字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试迁移laravel迁移,但出现错误:
I'm trying for migrate a laravel migration but i had an error :
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();
});
}
推荐答案
您可以通过手动设置字符串长度
You can set String Length manually by putting this
$table->string('name', 191); // You can put any number in exchange of 191
其他
将其放入APP->提供程序-> AppServiceProvider
Put This in APP -> Providers -> AppServiceProvider
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
这篇关于laravel migration指定的密钥太长;最大密钥长度为767字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文