我有以下错误。有人理解为什么?
php artisan migrate
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key
was too long; max key length is 767 bytes (SQL: alter table `users`
add unique `users_email_unique`(`email`))
create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name',255);
$table->string('email',255)->unique();
$table->string('password',255);
$table->rememberToken();
$table->timestamps();
});
答案 0 :(得分:3)
你要做的就是在App\Providers\AppServiceProvider
文件上编辑你的AppServiceProvider.php,并在boot方法中设置一个默认的字符串长度:
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
然后手动删除数据库,然后composer dump-autoload
和php artisan migrate
答案 1 :(得分:1)
修改AppServiceProvider.php
文件,您会在app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
然后运行
composer update
终端上的。然后尝试迁移您的脚本,这将解决您的问题。
答案 2 :(得分:1)
感谢所有留言
解决了下一个代码:
in config/database.php in mysql section
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
and replace them with with
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',