php craft project-config/apply is not properlly applying new changes to sites table and related elements.
php craft project-config/apply in the environment.projectconfig table, in sites table no primary site is set.This causes an craft\errors\SiteNotFoundException: No primary site exists error, and if you manually set primary column in sites table you will not be able to login to dashboard.
PHP version 7.4.10
OS version Linux 5.4.0-66-generic
Database driver & version MySQL 8.0.21
Image driver & version GD 7.4.10
Craft edition & version Craft Pro 3.6.8
Yii version 2.0.40
Twig version v2.14.3
Guzzle version 7.2.0
No plugins.
I stumbled upon a similar issue today, where a change of primary site isn't reflected correctly in project.yaml files.
If you have two sites, site1 and site2, where site1 is primary. Changing site2 to primary would update the yaml files but only for site2, leaving two sites with the flag primary: true. Now, on the current environment, DB would be updated correctly it seems, and it seems to work, but applying this via project.yaml (or just re-apply the whole config), would select probably the first site (alphabetically? don't really know) as primary yet again.
One have to manually edit the yaml file as of now. Tested in 3.6.9.
EDIT: Actually, when I did edit them manually and only keeping a single one of them as primary, I ended up with the error described from OP craft\errors\SiteNotFoundException: No primary site exists in /app/vendor/craftcms/cms/src/services/Sites.php:518 and now I need to figure out how to give myself access to the admin again...
Looks like the issue here is that when a new site was set as the primary, Craft wasn鈥檛 updating the project config of the prior primary site, to set primary: false. So then you鈥檇 deploy the project config to a new environment with two sites set to primary: true.
Just fixed that for the next release. If you see this happening locally, running php craft project-config/rebuild will fix it.
Craft 3.6.10 is out now with the fix for this. Note the fix is not retroactive though, so you will still need to run php craft project-config/rebuild.
@brandonkelly Seem to be working now. Thank you!