symfony服务器启动时的PostgreSQL错误

我正在学习 Symfony,我使用以下命令创建我的项目:symfony new myproject --full
在此之后我直接运行symfony serve

在控制台中,我收到了这些错误:

Tailing Web Server log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9.log)
Tailing PHP-FPM log file (/Users/ben/.symfony/log/cd52af540b09d661e4ffb4f5029da4bbaf3586a9/53fb8ec204547646acb3461995e4da5a54cc7575.log)
                                                                                                                        
 [OK] Web server listening                                                                                              
      The Web server is using PHP FPM 7.3.11                                                                            
      https://127.0.0.1:8000                                                                                            
                                                                                                                        

[Web Server ] Jun  3 23:38:48 |DEBUG  | PHP    Reloading PHP versions 
[Web Server ] Jun  3 23:38:48 |DEBUG  | PHP    Using PHP version 7.3.11 (from default version in $PATH) 
[Application] Jun  3 21:29:59 |CRITICA| REQUES Uncaught PHP Exception DoctrineDBALExceptionConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused    Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96 
[Application] Jun  3 21:29:59 |CRITICA| REQUES Exception thrown when handling an exception (DoctrineDBALExceptionConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:29:59 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Application] Jun  3 21:37:59 |ERROR  | REQUES Uncaught PHP Exception SymfonyComponentHttpKernelExceptionNotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/"" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136 
[Application] Jun  3 21:38:00 |ERROR  | REQUES Uncaught PHP Exception SymfonyComponentHttpKernelExceptionNotFoundHttpException: "No route found for "GET https://127.0.0.1:8000/favicon.ico" (from "https://127.0.0.1:8000/")" at /Users/ben/Desktop/symfonytuto/demo/vendor/symfony/http-kernel/EventListener/RouterListener.php line 136 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (DoctrineDBALExceptionConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:38:00 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Uncaught PHP Exception DoctrineDBALExceptionConnectionException: "An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused    Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432?" at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96 
[Application] Jun  3 21:38:00 |CRITICA| REQUES Exception thrown when handling an exception (DoctrineDBALExceptionConnectionException: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused   Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? at /Users/ben/Desktop/symfonytuto/demo/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php line 96) 
[Application] Jun  3 21:38:00 |CRITICA| PHP    Uncaught Exception: An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused     Is the server running on host "127.0.0.1" and accepting     TCP/IP connections on port 5432? 
[Web Server ] Jun  3 23:38:48 |INFO   | PHP    listening path="/usr/sbin/php-fpm" php="7.3.11" port=50170
[PHP-FPM    ] Jun  3 23:38:48 |NOTICE | FPM    fpm is running, pid 1240 
[PHP-FPM    ] Jun  3 23:38:48 |NOTICE | FPM    ready to handle connections 

在此之后,Symfony 的默认页面加载正确,但是当我向 url 添加路由时:例如:https://127.0.0.1:8000/testtt
我收到此错误:

An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

(应该是“这条路线不存在”之类的,不是吗?)

请告诉我如何向您提供有关我的问题的更多信息!

非常感谢 !

回答

这个问题经常出现,我认为在问题得到解决之前,答案是合适的。

假设您刚刚创建了一个新的 Symfony 网站框架应用程序,添加了一个新控制器并启动了开发服务器。您导航到新路线并抛出异常。要么得到“找不到驱动程序”或“可以连接到服务器”。这当然有点出乎意料,因为您尚未对数据库进行任何操作。

问题在于,Doctrine 迁移包为 Symfony 的分析器栏提供了一个数据收集器,在开发模式下运行时,该分析器栏会显示在浏览器页面的底部。数据收集器需要连接到数据库才能收集迁移数据。它不关心没有数据库的事实。它只是尝试连接并最终抛出异常。

我打开了一个问题。我仍然不完全确定这是一个功能还是错误。如果您愿意,请随时对该问题发表评论。

这是一个相当新的问题,尽管我没有准确跟踪它第一次出现的时间。因此,许多现有的教程和分步指南都没有提到它。将其视为您开发经验的一部分。学习如何阅读异常非常重要。

有几种解决方案。如果您计划使用数据库,请继续创建自己的数据库并调整 DATABASE_URL以指向它。数据库可以为空。迁移数据收集器只需要能够连接到它。在我的本地开发机器上,我实际上创建了一个名为 db_name 的数据库,只是为了避免出现此错误消息。

第二种解决方案是删除迁移包

composer remove doctrine/doctrine-migrations-bundle

问题就迎刃而解了。如果稍后您需要迁移,那么只需使用 composer require 重新安装它。

  • 这应该添加到文档“创建您的第一页”中或快速修复,因为从第一个文档练习中获取此错误非常令人困惑和沮丧。还是只有我或“未找到驱动程序”无助于了解发生了什么?

以上是symfony服务器启动时的PostgreSQL错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>