我正在尝试迁移 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`))
Run Code Online (Sandbox Code Playgroud)
我的代码是:
if (!Schema::hasTable('password_resets')) {
Schema::create('password_resets', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
Run Code Online (Sandbox Code Playgroud)
您可以手动设置字符串长度
$table->string('name', 191); // You can put any number in exchange of 191
Run Code Online (Sandbox Code Playgroud)
别的
把这个放在 APP -> Providers -> AppServiceProvider
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6611 次 |
| 最近记录: |