3

I cannot run symfony local server by command: php bin/console server:run. I get error: [Symfony\Component\Console\Exception\LogicException] An option named "connection" already exists.

Dependencies in 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

I think these parameters in parameters.yml used to work earlier. I use mysql and also sqlite for tests.

2
  • 1
    What about your parameters.yml? Can we see that? You may have listed your database connection twice. Or named two connections the same thing. Commented Mar 17, 2021 at 22:57
  • I added the parameters.yml content. As you can see I have nothing to hide ;). Commented Mar 18, 2021 at 19:52

3 Answers 3

8

I faced the same issue in a Symfony v4.2 project, without changing anything in my code base.

As already found in this issue https://github.com/doctrine/dbal/issues/4565
it appears in certain versions of the doctrine/doctrine-bundle package (in my case v1.11). The RunSqlDoctrineCommand.php from vendor adds the second option which causes the error.

If you can update your doctrine/doctrine-bundle package, you might be fine. In my case, an update or fix by package was not possible.

What can we do in that case?

What comes next is more a hack, than a real good solution, so use it at your own risk!

As statet in the commit from official repository: https://github.com/doctrine/DoctrineBundle/commit/86d2469d6be06d55ad7b9e2f076f6942476f2e87 (thanks to the guys in issue above)
I made a copy of the new RunSqlDoctrineCommand.php from that commit and save it in my project as dist/RunSqlDoctrineCommand.php.

In composer.json change the scripts sections as follows:

{
    "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"
        ]
    }
}

This will just copy and override the original file in vendor directory on every composer install/update. This will only work on a unix/linux system, btw.

As said: Not the best solution, but it keeps your project in shape.

Sign up to request clarification or add additional context in comments.

Comments

0

In this answer is there is a good explanation

in my case

composer update doctrine/doctrine-bundle

Comments

0

Inside (symfony project) vendor/doctrine/doctrine-bundle/Command/Proxy/RunSqlDoctrineCommand.php change configure function like below:

protected function configure()
{
    parent::configure();

    $this
        ->setName('doctrine:query:sql')
        //->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The 
        connection to use for this command')
        ->setHelp(<<<EOT
        The <info>%command.name%</info> command executes the given SQL query and
        outputs the results:

        <info>php %command.full_name% "SELECT * FROM users"</info>
        EOT
    );
    if ($this->getDefinition()->hasOption('connection')) {
        return;
    }

    $this->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The 
    connection to use for this command');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.