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

[3.4] Project config can't connect to database after install #5697

Closed
janhenckens opened this issue Feb 21, 2020 · 5 comments
Closed

[3.4] Project config can't connect to database after install #5697

janhenckens opened this issue Feb 21, 2020 · 5 comments

Comments

@janhenckens
Copy link
Contributor

Description

When starting a project from our starter repo, we're running into the following error:

After installing, the setup script will try to apply the existing project.yaml but that throws the following error: can't apply existing project config: Craft CMS can’t connect to the database with the credentials in config/db.php., eventhough seconds earlier it was able to install without any issues.

    > add foreign key userpreferences_userId_fk: {{%userpreferences}} (userId) references {{%users}} (id) ... done (time: 0.028s)
    > add foreign key users_id_fk: {{%users}} (id) references {{%elements}} (id) ... done (time: 0.017s)
    > add foreign key users_photoId_fk: {{%users}} (photoId) references {{%assets}} (id) ... done (time: 0.021s)
    > add foreign key volumefolders_parentId_fk: {{%volumefolders}} (parentId) references {{%volumefolders}} (id) ... done (time: 0.019s)
    > add foreign key volumefolders_volumeId_fk: {{%volumefolders}} (volumeId) references {{%volumes}} (id) ... done (time: 0.028s)
    > add foreign key volumes_fieldLayoutId_fk: {{%volumes}} (fieldLayoutId) references {{%fieldlayouts}} (id) ... done (time: 0.025s)
    > add foreign key widgets_userId_fk: {{%widgets}} (userId) references {{%users}} (id) ... done (time: 0.018s)
    > populating the info table ... done
    > can't apply existing project config: Craft CMS can’t connect to the database with the credentials in config/db.php.
    > renaming project.yaml to project-20200208-083243.yaml and moving to config backup folder ... done

Testing this with the previous version of the repo (1.4.2, which ran Craft 3.3.19) it did work, the latest release (on Craft 3.4.7.1) has the error.

Steps to reproduce

  1. Run composer create-project statikbe/craft test
  2. Run test/craft setup and install Craft

Additional info

  • Craft version: 3.4.7.1
  • PHP version: 7.3.8
  • Database driver & version: 5.7.28
@janhenckens
Copy link
Contributor Author

Found the issue. config/db.php still had server, database and driver settings. Replacing those with the DSN fixed it.

Still strange that it worked for the rest of the install though....

@brandonkelly
Copy link
Member

Still strange that it worked for the rest of the install though....

I can see how that could possibly happen, if you started with the ./craft setup command which sets all the DB connection preferences, and then answered yes to the Install Craft now? prompt, which would end up installing Craft using the same DB connection that the setup command already established, rather than going through .env + config/db.php.

@janhenckens
Copy link
Contributor Author

@brandonkelly can I pick your brain on this one a second thime?

My config/db.php and .env match Craft's and still I'm getting the same error.

Running composer create-project statikbe/craft test should show give you the error. It still creates all tables and but errors out when creating the user
When I then delete the tables and run the setup again, it works. (probably because then it already had the .env & config/db.php values.

I can only reproduce it with our project.yaml, not with craftcms/craft.

Appreciate any help you could provide!

@brandonkelly
Copy link
Member

@janhenckens I was able to reproduce using your starter repo. Issue ended up being due to another change in 3.4, which is that craft\queue\Queue now stores its own reference to the db component internally (to be more like yii\queue\db\Queue), and that wasn’t getting updated when the app’s db component got swapped out based on the updated connection settings.

Fixed for the next release, by reconfiguring the existing db component once the connection settings are defined, rather than swapping it out with a new one.

@brandonkelly
Copy link
Member

Craft 3.4.9 is out now with the fix.

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

No branches or pull requests

2 participants