laravel执行php artisan migrate报错是因为没有开启扩展“php_pdo_mysql.dll”,其解决办法就是打开“php.ini”文件并开启“php_pdo_mysql.dll”扩展即可。
laravel执行php artisan migrate报错怎么办?
报错一
$ php artisan migrate illuminate\database\queryexception : could not find driver (sql: select * from information_schema.tables where table_schema = dev_oms and table_name = migrations) at d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:664 660| // if an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with sql, which will make this exception a 662| // 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), $e 666| ); 667| } 668| exception trace: 1 pdoexception::("could not find driver") d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connectors\connector.php:68 2 pdo::__construct("mysql:host=127.0.0.1;port=3306;dbname=dev_oms", "root","root", []) d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connectors\connector.php:68 please use the argument -v to see more details.
原因是php.ini 扩展"php_pdo_mysql.dll"没开启
报错二
$ php artisan migratemigration table created successfully. 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 `users` add unique `users_email_unique`(`email`)) at d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:664 660| // if an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with sql, which will make this exception a 662| // 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), $e 666| ); 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\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:458 2 pdostatement::execute() d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:458 please use the argument -v to see more details.
数据库编码改为utf8mb4
报错三
$ php artisan migratemigration table created successfully. 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 `users` add unique `users_email_unique`(`email`)) at d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:664 660| // if an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with sql, which will make this exception a 662| // 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), $e 666| ); 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\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:458 2 pdostatement::execute() d:\www\dev_oms\vendor\laravel\framework\src\illuminate\database\connection.php:458 please use the argument -v to see more details.
加上两行代码即可
推荐:《laravel开发》