当前位置:网站首页>laravel table migration error [easy to understand]

laravel table migration error [easy to understand]

2022-08-09 23:13:00 The whole stack programmer webmaster

Hello everyone, meet again, I'm your friend Quanstack Jun.

error infomation:

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error oraccess violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))at D:\WWW\test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664660| // If an exception occurs when attempting to run a query, we'll format the error661| // message to include the bindings with SQL, which will make this exception a662| // lot more helpful to the developer instead of just the database's errors.663| catch (Exception $e) {> 664| throw new QueryException(665| $query, $this->prepareBindings($bindings), $e666| );667| }668|Exception trace:1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")D:\WWW\test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:4582 PDOStatement::execute()D:\WWW\test\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458Please use the argument -v to see more details.

Solution: Index length & Mysql / MariaDB Laravel uses utf8mb4 encoding by default, which supports storing emojis in the database.If you are creating an index on a MySQL version lower than 5.7.7 or MariaDB version lower than 10.2.2, then you need to manually configure the default string length for database migrations.That is, call the Schema::defaultStringLength method in AppServiceProvider to configure it:

use Illuminate\Support\Facades\Schema;/** * Boot any application service * * @return void */public function boot(){Schema::defaultStringLength(191);}

Publisher: Full-stack programmer, please indicate the source: https://javaforall.cn/105807.htmlOriginal link: https://javaforall.cn

原网站

版权声明
本文为[The whole stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208092049543542.html