Laravel 5.6.17 php artisan 迁移错误 php 7.2
Laravel 5.6.17 php artisan migration error with php 7.2
我正在使用 laravel 5.6.17 和 php 7.2;当我 运行 php artisan migrate
命令时,我收到以下错误。
有关详细信息,已在声明的数据库中创建默认表 "users" 和 "migrations"。
laravel不支持php7.2??
Image: laravel 5.6.17 php artisan migrate error
Migration 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:\xampp\htdocs\laravel\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:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
2 PDOStatement::execute()
D:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
Please use the argument -v to see more details.
在 AppServiceProvider.php 中,您将此代码包含在文件顶部。
use Illuminate\Support\Facades\Schema;
然后你在启动方法中添加这段代码
Schema::defaultStringLength(191);
是的,我得到了答案
只需从您的根目录中转到以下文件<ROOT>/app/Providers/AppServiceProvider.php
之后:
1) 在文件的顶部导入架构:use Illuminate\Support\Facades\Schema;
2) 并在boot方法中定义字符串的长度:Schema::defaultStringLength(191);
// Import Schema
use Illuminate\Support\Facades\Schema;
// ...
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Add the following line
Schema::defaultStringLength(191);
}
// ...
}
我正在使用 laravel 5.6.17 和 php 7.2;当我 运行 php artisan migrate
命令时,我收到以下错误。
有关详细信息,已在声明的数据库中创建默认表 "users" 和 "migrations"。
laravel不支持php7.2??
Image: laravel 5.6.17 php artisan migrate error
Migration 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:\xampp\htdocs\laravel\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:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
2 PDOStatement::execute()
D:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
Please use the argument -v to see more details.
在 AppServiceProvider.php 中,您将此代码包含在文件顶部。
use Illuminate\Support\Facades\Schema;
然后你在启动方法中添加这段代码
Schema::defaultStringLength(191);
是的,我得到了答案
只需从您的根目录中转到以下文件<ROOT>/app/Providers/AppServiceProvider.php
之后:
1) 在文件的顶部导入架构:use Illuminate\Support\Facades\Schema;
2) 并在boot方法中定义字符串的长度:Schema::defaultStringLength(191);
// Import Schema
use Illuminate\Support\Facades\Schema;
// ...
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
// Add the following line
Schema::defaultStringLength(191);
}
// ...
}