Laravel 5.6.17 php工匠迁移错误与PHP 7.2

时间:2018-04-23 06:03:41

标签: php laravel-5.6

我正在使用laravel 5.6.17和php 7.2;当我运行php artisan migrate命令时,我收到以下错误。

有关详细信息,请使用默认表"用户"和#34;迁移"已在声明的数据库中创建。

没有laravel支持php 7.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.

2 个答案:

答案 0 :(得分:5)

在AppServiceProvider.php中,您将此代码包含在文件顶部。

use Illuminate\Support\Facades\Schema;

然后在引导方法中添加此代码

Schema::defaultStringLength(191);

答案 1 :(得分:4)

是的,我得到了答案on the following link...

只需从根目录<ROOT>/app/Providers/AppServiceProvider.php

中转到以下文件即可

之后:

1)在文件顶部的导入架构:use Illuminate\Support\Facades\Schema;

2)并在引导方法中定义字符串的长度:Schema::defaultStringLength(191);

// Import Schema
use Illuminate\Support\Facades\Schema;
// ...

class AppServiceProvider extends ServiceProvider
{

public function boot()
{
    // Add the following line
    Schema::defaultStringLength(191);
}

// ...

}