ฉันมีปัญหากับชุด Doctrine Migration บน Symfony 4 ฉันเริ่มเว็บแอปพลิเคชันในคอนเทนเนอร์ Docker เมื่อพยายามดำเนินการย้ายข้อมูลหลังจากคอนเทนเนอร์เริ่มต้นแล้ว การโยกย้ายจะล้มเหลวโดยมีข้อยกเว้น "การเชื่อมต่อถูกปฏิเสธ" แต่:
- เมื่อฉันพยายามเชื่อมต่อกับ MySQL ในคอนเทนเนอร์ของตัวเองจากโฮสต์หรือคอนเทนเนอร์ FPM มันก็ทำงานได้ดี
- ในการดำเนินการตามคำสั่งซึ่งใช้หลักคำสอนก็ทำงานได้ดี
ตัวอย่าง:
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: Misd\PhoneNumberBundle\Doctrine\DBAL\Types\PhoneNumberType
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: 'App\Entity'
alias: App
การกำหนดค่าการย้ายหลักคำสอนเป็นค่าเริ่มต้น:
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations