Reputation: 11
Symfony 7 Multiple Entities does not work correctly.
I use Symfony 7 in a test setup with 3 databases. However, the migration does not work correctly. All tables are always created in each database. This should not be the case. I create an entity outside the default connection with "php bin/console make:entity Logs\LogTable". Then php bin/console doctrine:migrations:diff --em=logs and php bin/console doctrine:migrations:migrations --em=logs. The commands are executed, but not the way I want.
Here is my configuration in the doctrine.yaml
Does anyone have a suggested solution?
doctrine:
dbal:
connections:
default:
url: '%env(resolve:DATABASE_URL_1)%'
use_savepoints: true
profiling_collect_backtrace: '%kernel.debug%'
logs:
url: '%env(resolve:DATABASE_URL_2)%'
profiling_collect_backtrace: '%kernel.debug%'
sys:
url: '%env(resolve:DATABASE_URL_3)%'
use_savepoints: true
profiling_collect_backtrace: '%kernel.debug%'
default_connection: default
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '16'
#profiling_collect_backtrace: '%kernel.debug%'
#use_savepoints: true
orm:
default_entity_manager: default
entity_managers:
default:
auto_mapping: false
connection: default
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
Main:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/Main'
prefix: 'App\Entity\Main'
alias: Main
logs:
auto_mapping: false
connection: logs
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
Logs:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/Logs'
prefix: 'App\Entity\Logs'
alias: Logs
sys:
auto_mapping: false
connection: sys
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
Logs:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity/Sys'
prefix: 'App\Entity\Sys'
alias: Sys
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
Upvotes: 0
Views: 181
Reputation: 438
Hi how i solved the problem:
config/packages/doctrine_migrations.yaml
doctrine_migrations:
migrations_paths:
'DoctrineMigrations\Main': '%kernel.project_dir%/migrations/main'
'DoctrineMigrations\Logs': '%kernel.project_dir%/migrations/logs'
...
then when you generate migration:
php bin/console doctrine:migrations:diff --em=logs --namespace="DoctrineMigrations\Logs"
the funny part is that when you run
php bin/console doctrine:migrations:migrate --em=logs
symfony knows about correct path
Upvotes: 0