学说迁移 - 连接被拒绝



我在Symfony 4上使用Doctrine Migration捆绑包时遇到了问题。我在 Docker 容器中启动我的 Web 应用程序。在容器启动后执行迁移时,迁移失败并出现"连接被拒绝"异常。但:

  • 当我尝试从主机或 FPM 容器连接到它自己的容器中的 MySQL 时,它工作正常
  • 在执行使用教义的命令时,它工作正常。

例:

root@3af0cf70b099:/var/www# php bin/console doctrine:migration:migrate -qn
In StreamSocketClient.php line 225:
Failed to write to socket: fwrite(): send of 185 bytes failed with errno=111 Connection refused (8)

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
root@3af0cf70b099:/var/www# php bin/console dbtest

[OK] Found user with login demo

root@3af0cf70b099:/var/www# php bin/console doctrine:migration:migrate -qn
In StreamSocketClient.php line 225:
Failed to write to socket: fwrite(): send of 185 bytes failed with errno=111 Connection refused (8)

doctrine:migrations:migrate [--write-sql [WRITE-SQL]] [--dry-run] [--query-time] [--allow-no-migration] [--configuration [CONFIGURATION]] [--db-configuration [DB-CONFIGURATION]] [--db DB] [--em EM] [--shard SHARD] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> [<version>]
root@3af0cf70b099:/var/www#

迁移仅在容器启动后超过 20 秒后有效。
我的学说配置:

doctrine:
dbal:
# configure these for your database server
driver: '%env(DB_DRIVER)%'
server_version: '%env(DB_SERVER_VERSION)%'
charset: '%env(DB_CHARSET)%'
default_table_options:
charset: '%env(DB_CHARSET)%'
collate: '%env(DB_COLLATION)%'
mapping_types:
enum: string
types:
phone_number: MisdPhoneNumberBundleDoctrineDBALTypesPhoneNumberType
url: 'mysql://%env(DB_USER)%:%env(MYSQL_ROOT_PASSWORD)%@%env(DB_HOST)%:%env(DB_PORT)%/%env(MYSQL_DATABASE)%'
orm:
auto_generate_proxy_classes: false
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App

原则迁移配置是默认的:

doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from AppMigrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations

您需要等待所有 docker 服务完全加载。 请参阅:https://docs.docker.com/compose/startup-order/

相关内容

  • 没有找到相关文章

最新更新