Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install doctrine/dbal with recent Laravel Installations #49403

Closed
KentarouTakeda opened this issue Dec 16, 2023 · 6 comments
Closed

Cannot install doctrine/dbal with recent Laravel Installations #49403

KentarouTakeda opened this issue Dec 16, 2023 · 6 comments
Labels

Comments

@KentarouTakeda
Copy link
Contributor

KentarouTakeda commented Dec 16, 2023

Laravel Version

10.37.3 / probably all versions

PHP Version

8.3.0 / probably all versions

Database Driver & Version

N/A

Description

Dependency resolution with composer require doctrine/dbal fails in a recently Laravel installation.
(This may not be caused by Laravel itself)

Here is a summary of the failures:

  1. composer create-project laravel/laravel

    • laravel/framework v10.37.3 requires nesbot/carbon (^2.67)
      • resolved to 2.72.1
    • nesbot/carbon 2.72.1 requires carbonphp/carbon-doctrine-types (*)
      • resolved to 3.1.0
  2. composer require doctrine/dbal

    • carbonphp/carbon-doctrine-types 3.1.0 conflicts with doctrine/dbal 3.7.2

Previously this did not occur. This issue now occurs due to the following changes in nesbot/carbon.

briannesbitt/Carbon@4d06802#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34

In short, Laravel applications installed after November 28, 2023, when the above changes were published, will not be able to install doctrine/dbal in the normal way.

For now, the workaround would be:

UPDATED: 2023-12-20 12:09 JST
Fixed since a better procedure was mentioned in the comments.

  1. Manually add { "require": { "doctrine/dbal":"^3.5.1" } } to composer.json.
    Run composer require doctrine/dbal carbonphp/carbon-doctrine-types
  2. Run composer update
    Here carbonphp/carbon-doctrine-types will be DOWNGRADED to 2
  3. Then, doctrine/dbal is installed without any problems.

This is not a problem with Laravel, but given that special installation steps are required and packages may be downgraded during this process, some countermeasures may be necessary.
(But I don't know your package dependency policy, so I don't have any ideas, sorry)

Steps To Reproduce

sh-3.2$ composer create-project laravel/laravel

### omission

> @php artisan key:generate --ansi

   INFO  Application key set successfully.

sh-3.2$ cd laravel
sh-3.2$ php artisan model:show User

 ┌ Inspecting database information requires the Doctrine DBAL (doctrine/dbal) package. Would you like to install it? ┐
 │ Yes                                                                                                               │
 └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

./composer.json has been updated
Running composer update doctrine/dbal
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires doctrine/dbal ^3.5.1 -> satisfiable by doctrine/dbal[3.5.1, ..., 3.7.2].
    - nesbot/carbon 2.72.1 requires carbonphp/carbon-doctrine-types * -> satisfiable by carbonphp/carbon-doctrine-types[3.1.0].
    - laravel/framework v10.37.3 requires nesbot/carbon ^2.67 -> satisfiable by nesbot/carbon[2.72.1].
    - carbonphp/carbon-doctrine-types 3.1.0 conflicts with doctrine/dbal 3.7.2.
    - laravel/framework is locked to version v10.37.3 and an update of this package was not requested.


Installation failed, reverting ./composer.json and ./composer.lock to their original content.
@mbabker
Copy link
Contributor

mbabker commented Dec 18, 2023

I'd almost close this as a "won't fix". To actually fix this transparently in the model:show command (and maybe others where the framework's trying to update your dependencies), Laravel would need to run composer require or composer update with the -W flag, which would force Composer to update all of your project's dependencies instead of only adding/updating the packages the command is trying to add. I'd personally argue that if the framework can't add/update a single package on its own, it's safer to fail like it is now versus making unexpected changes to the project's dependency chain.

The reason you're getting this error is that the initial install is bringing in carbonphp/carbon-doctrine-types on its 3.x branch, which is only compatible with the upcoming DBAL 4.0 release. So adding the doctrine/dbal dependency after the initial install also requires downgrading carbonphp/carbon-doctrine-types to its 2.x branch which is compatible with DBAL 3.x.

@driesvints
Copy link
Member

Dependency resolution with composer require doctrine/dbal fails in a recently Laravel installation.

Think this got fixed because I can run this fine now.

@taylorotwell
Copy link
Member

Not fixed.

@timacdonald
Copy link
Member

Attempting to resolve this over here #49438

For anyone landing here, you will need to run the following to install DBAL:

composer require doctrine/dbal carbonphp/carbon-doctrine-types

@KentarouTakeda
Copy link
Contributor Author

That method seemed better, so I modified the description at the beginning.

@driesvints driesvints added the bug label Dec 20, 2023
@timacdonald
Copy link
Member

We've fixed this as best we can in #49438

Again, anyone dropping by with this issue, please run:

composer require doctrine/dbal carbonphp/carbon-doctrine-types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants