I've inherited a Symfony project that uses a MySQL DB. I need to create a second database. I've changed the …/htdocs/projectFolder/app/config/parameters.yml to have a new dbName.
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: 8889
database_name: inherited_db_name
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
locale: en
secret: nosecret
database_path: null
Changed to:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1 #can't use "localhost"
database_port: 8889
database_name: new_db_to_create
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
locale: en
secret: nosecret
database_path: null
I have tried all the tricks I can thing of but the command: doctrine:database:create
just keeps trying to create “inherited_db_name”
If I drop the “inherited_db_name” DB and then run the command again w/ the new parameters.yml the “inherited_db_name” is recreated. I've searched and grep-ed for the “inherited_db_name” but cannot find out where it's coming from. ANY suggestions would be welcomed.
You should configure your Symfony2 application to manage both databases.
So your parameters.yml file will look like:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: 8889
database_name: inherited_db_name
database_user: root
database_password: root
database_driver2: pdo_mysql
database_host2: 127.0.0.1 #can't use "localhost"
database_port2: 8889
database_name2: new_db_to_create
database_user2: root
database_password2: root
mailer_transport: smtp
mailer_host: localhost
mailer_user: null
mailer_password: null
locale: en
secret: nosecret
database_path: null
Now you just need to configure Doctrine properly:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
customer:
driver: "%database_driver2%"
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AcmeDemoBundle: ~
AcmeStoreBundle: ~
customer:
connection: customer
mappings:
AcmeCustomerBundle: ~
Please take a look to the Symfony2 cookbook: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.