在使用laravel框架开发php时我们可以使用laravel的迁移机制来快速的创建表及填充数据今天在使用laravel的时候执行php artisan migrate
时报错了SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length于是百度解决方法修改config/database.php文件找到mysql配置项将
'charset' => 'utf8mb4','collation' => 'utf8mb4_unicode_ci',
修改为
charset' => 'utf8',collation' => 'utf8_unicode_ci',
或者在appProvidersAppServiceProvider中调用Schema::defaultStringLength方法来实现配置。
use Illuminate\Support\Facades\Schema;/** Bootstrap any application services.** @return void*/public function boot(){ Schema::defaultStringLength(191);}
推荐