【问题标题】:error when executing php artisan migrate seed in console在控制台中执行 php artisan migrate seed 时出错
【发布时间】:2021-09-25 19:29:36
【问题描述】:

我在项目根文件夹的控制台写php artisan migrate:fresh --seed,当我运行这个命令时,大约需要1分钟然后它返回\

在 PackageServiceProvider.php 第 14 行:

语法错误、意外的“包”(T_STRING)、期望函数 (T_FUNCTION) 或 const (T_CONST)

PackageServiceProvider.php:

namespace Spatie\LaravelPackageTools;

use Carbon\Carbon;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use ReflectionClass;
use Spatie\LaravelPackageTools\Exceptions\InvalidPackage;

abstract class PackageServiceProvider extends ServiceProvider
{
    protected Package $package; /*  line 14 */

    abstract public function configurePackage(Package $package): void;

    public function register()
    {
        $this->registeringPackage();

        $this->package = new Package();

        $this->package->setBasePath($this->getPackageBaseDir());

        $this->configurePackage($this->package);

        if (empty($this->package->name)) {
            throw InvalidPackage::nameIsRequired();
        }

        foreach($this->package->configFileNames as $configFileName) {
            $this->mergeConfigFrom($this->package->basePath("/../config/{$configFileName}.php"), $configFileName);
        }

        $this->packageRegistered();

        return $this;
    }
.
.
.
.
}

项目作者的PHP版本:7.4.19
我的 PHP 版本:7.3.27
我是 laravel 的菜鸟,所以如果我必须提供有关该问题的更多信息,请告诉我。 \

编辑

将 PHP 版本更新到 7.4.21
我写了命令,它返回了

C:\xampp\htdocs\Business-Manager>php artisan migrate:fresh --seed
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > y


   Illuminate\Database\QueryException

  SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')

  at C:\xampp\htdocs\Business-Manager\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
    688▕         // If an exception occurs when attempting to run a query, we'll format the error
    689▕         // message to include the bindings with SQL, which will make this exception a
    690▕         // lot more helpful to the developer instead of just the database's errors.
    691▕         catch (Exception $e) {
  ➜ 692▕             throw new QueryException(
    693▕                 $query, $this->prepareBindings($bindings), $e
    694▕             );
    695▕         }
    696▕

  1   C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDO\Exception.php:18
      Doctrine\DBAL\Driver\PDO\Exception::("SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)")

  2   C:\xampp\htdocs\Business-Manager\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:43
      Doctrine\DBAL\Driver\PDO\Exception::new(Object(PDOException))

我的 MySQL 帐户: enter image description here

【问题讨论】:

  • 更新你的php版本到7.4+
  • @OMIShah 你能再检查一下这个问题吗
  • 是MySQL用户名密码访问问题。您提供了错误的 MySQL 用户名或密码
  • 100% 正确,在 .env 文件中也一样
  • Lmao,您已在 .environment 文件中将 forge 设置为用户名,但您的 MySQL 表中有一个用户名为 root 的用户!

标签: laravel laravel-artisan artisan-migrate


【解决方案1】:

你的问题是 protected Package $package; 是 PHP 7.4,应该是 protected $package;

正如您在source code 中看到的,它需要php ^7.4^8.0,因此您必须将您的PHP 更改为其中任何一个。

This is another 查看您正在下载的作曲家包的位置,以查看有关它的更多信息...

【讨论】:

  • 我升级版本再写命令,我更新问题你看看有什么新问题
  • 您在.env 中的数据库用户名和密码不正确
【解决方案2】:

在顶部导入合适的类。

use Facade\Ignition\Support\Packagist\Package;

【讨论】:

    猜你喜欢
    • 2018-07-31
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多