Reputation: 2683
In my project, I have to separated databases, which I set up like this:
// app/config/parameters.yml
parameters:
#base
database_host: 127.0.0.1
database_port: null
database_name: nm_admin
database_user: nm_admin
database_password: 'nm_admin'
#user1
database_host_user1: 127.0.0.1
database_port_user1: null
database_name_user1: nm_user1
database_user_user1: nm_user1
database_password_user1: 'nm_user1'
// app/config/config.yaml
doctrine:
dbal:
default_connection: default
connections:
#default
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
#user1
user1:
driver: pdo_mysql
host: "%database_host_user1%"
port: "%database_port_user1%"
dbname: "%database_name_user1%"
user: "%database_user_user1%"
password: "%database_password_user1%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
#default
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: false
connection: default
mappings:
AppBundle: ~
#user1
user1:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: false
connection: user1
mappings:
AppBundle: ~
Now, when I create an Entity for the databases, like this
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="app_clients")
* @ORM\HasLifecycleCallbacks
* @ORM\Entity(repositoryClass="AppBundle\Entity\ClientRepository")
*/
class Client
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
protected $mailbox;
}
with php app/console doctrine:schema:update --force
it always puts it to the nm_admin database (the default one).
The docs for Doctrine do not say anything about selecting a schema, here but is there a way? I want certain entities to belong to nm_user and some to nm_admin, how can I define that?
Upvotes: 2
Views: 93
Reputation: 3135
Try to update the second db by this way:
php app/console doctrine:schema:update --force --em=user1
And have a look to: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html
Upvotes: 3