4
votes

How do I tell Symfony to generate tables for just one Bundle?

Every time I create a bundle and run:

php app/console doctrine:schema:create

It creates on my current database (of the specific bundle) ALL tables from ALL of my bundles. And I don't need that.

4
app/console doctrine:schema:update --em my_own_entity_manager_name using this command, doesn't work for me, It still creating the entities from all bundles. - Roberto Cardenas

4 Answers

2
votes

When you create a new bundle, just use

app/console doctrine:schema:update

Since your schema exists already.

2
votes

Sometimes using php app/console doctrine:schema:update --force doesn't resolve the problem, so you can simply comment other bundles from the AppKernel.php in $bundles and then use php app/console doctrine:schema:update --force again, it should work.

Don't forget to uncomment commented bundles.

1
votes

If your bundles are mapped to different entity managers, you can (or must) use the argument "--em entity_manager_name" for the schema update command.

Example:

app/console doctrine:schema:update --em my_own_entity_manager_name
1
votes

Suppose you have a Bundle that uses a MySQL database that is inside a folder in the src directory, for example :

src/Folder/BundleFolder/

And another Bundle that uses a Postgresql database that is in your src directory, let's say :

src/OtherBundle

To map doctrine to a certain entity managers use this conf in your app/config/config.yml file :

orm:
    #auto_mapping: true 
    #default_entity_manager: default
    entity_managers:
        default:
            connection: mysql
            mappings:
                FolderBundleFolder : ~
        other:
            connection: pgsql
            mappings:
                OtherBundle : ~

Then as user3580495 said, use the command :

php app/console doctrine:schema:create --em=other --dump-sql

to see what is going to happen on the postgresql database.

php app/console doctrine:schema:update --em=default --dump-sql

will show you the SQL commands that are going to be executed on the MySQL database.

In the conf file file, don't forget the comment like this :

#auto_mapping: true 
#default_entity_manager: default

That also means that when you use that doctrine update command, you will have to precise your entity manager each time, which gives you more control over what you do on the overall.

Don't forget that the --help parameter is always your friend for symfony commands and also you will find a lot of info in the docs :

http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html