【问题标题】:Symfony\Component\Console\Exception\LogicException during php bin/console server:runSymfony\Component\Console\Exception\LogicException 在 php bin/console server:run
【发布时间】:2021-03-17 19:56:28
【问题描述】:

我无法通过以下命令运行 symfony 本地服务器:php bin/console server:run。 我得到错误: [Symfony\组件\控制台\异常\逻辑异常] 一个名为“connection”的选项已经存在。

composer.json 中的依赖项:

"require": {
        "php": "^7.0, <7.4",
        "composer/package-versions-deprecated": "^1.11",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "incenteev/composer-parameter-handler": "^2.0",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^3.0.2",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "3.3.*",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "doctrine/data-fixtures": "^1.3",
        "doctrine/doctrine-fixtures-bundle": "^2.3",
        "liip/functional-test-bundle": "^1.8",
        "phpunit/phpunit": "^6.3",
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^3.0"
    },

parameters.yml:

# This file is auto-generated during the composer install
parameters:
    database_host: 127.0.0.1
    database_port: 3306
    database_name: tests
    database_user: root
    database_password: password
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: ThisTokenIsNotSoSecretChangeIt

我认为parameters.yml 中的这些参数以前可以工作。 我使用 mysql 和 sqlite 进行测试。

【问题讨论】:

  • 你的parameters.yml呢?我们能看到吗?您可能已经列出了两次数据库连接。或者将两个连接命名为相同的东西。
  • 我添加了parameters.yml内容。如您所见,我没有什么可隐瞒的;)。

标签: symfony symfony-3.3


【解决方案1】:

我在 Symfony v4.2 项目中遇到了同样的问题,而我的代码库中没有任何更改。

正如在本期中已经发现的那样https://github.com/doctrine/dbal/issues/4565
它出现在 doctrine/doctrine-bundle 包的某些版本中(在我的例子中是 v1.11)。来自供应商的RunSqlDoctrineCommand.php 添加了导致错误的第二个选项。

如果您可以更新您的 doctrine/doctrine-bundle 软件包,您可能会没事。就我而言,无法按包进行更新或修复。

在这种情况下我们能做什么?

接下来的内容更像是一个 hack,而不是一个真正好的解决方案,所以使用它需要您自担风险!

正如官方存储库提交中的声明:https://github.com/doctrine/DoctrineBundle/commit/86d2469d6be06d55ad7b9e2f076f6942476f2e87(感谢上述问题的人)
我从该提交中复制了新的RunSqlDoctrineCommand.php,并将其保存在我的项目中为dist/RunSqlDoctrineCommand.php。

在composer.json 中更改scripts 部分如下:

{
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd"
        },
        "doctrine-bugfix": [
            "cp -f dist/RunSqlDoctrineCommand.php vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php"
        ],
        "post-install-cmd": [
            "@auto-scripts",
            "@doctrine-bugfix"
        ],
        "post-update-cmd": [
            "@auto-scripts",
            "@doctrine-bugfix"
        ]
    }
}

这只会在每个composer install/update 上复制并覆盖供应商目录中的原始文件。顺便说一句,这只适用于 unix/linux 系统。

如前所述:不是最好的解决方案,但它可以让您的项目保持良好状态。

【讨论】:

    【解决方案2】:

    在这个answer有没有很好的解释

    就我而言

    composer update doctrine/doctrine-bundle
    

    【讨论】:

      猜你喜欢
      • 2022-01-08
      • 2017-08-04
      • 2018-09-03
      • 2016-07-24
      • 2018-12-24
      • 1970-01-01
      • 2021-09-05
      • 2015-05-12
      • 2018-04-27
      相关资源
      最近更新 更多