Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The doctrine:database:create command will not populate the structure of the tables but rather create the database on your database manager like MySQL. To populate the database structure, use the <code>doctrine:schema:create</code> command for the initial creation of the structure and the <code>doctrine:schema:update --force</code> command when you want to update the structure after you made some modifications to the annotations. </p> <p>As you have mentionned, you need to configure some parameters in Symfony2 for Doctrine to work correctly. Those parameters need to be set in the config.yml configuration file that you can find in the app/config folder of the standard Symfony2 distribution. Here's a sample of the configuration you need to add to the config.yml file:</p> <pre><code># Doctrine Services Configuration doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: localhost port: 3396 dbname: dbname_dev user: dbname_dev password: yourpassword logging: "%kernel.debug%" orm: auto_generate_proxy_classes: "%kernel.debug%" default_entity_manager: default entity_managers: default: mappings: AcmeBundle: ~ </code></pre> <p>The first part of the configuration, the dbal part, is used configure your database connection information. I would suggest you to first test the connection with the root account of your database and then when everything is working well, change the settings to use a dedicated user. This way, you are sure that you don't have some privileges problems or other kind of problems that could be related to the dedicated user.</p> <p>The second part, the orm part, is use to configure the mapping of your entities to the database. This part is required if you want Symfony2 to populate the database structure automatically. Replace AcmeBundle with the name of your bundle in the sample above to enable the orm functionalities in your project.</p> <p>On a side note, the Symfony2 team is working on simplifying the configuration and I think there is now an easier way to configure the Doctrine parameters. The sample I propose you is the one I am using right now with the Beta1 of Symfony2.</p> <p>And finally to answer your question, I think the best is to let Symfony2 deals with the creation and update the database structure. One argument in favor of this would be that you don't need to maintain an SQL file dealing with the database structure. This information is implicitely held by the annotations in your entity so you just have to change you annotations and call the <code>doctrine:schema:update --force</code> command to update the structure. With this in mind, you should not create the structure before hand but let Symfony2 create it for you. </p> <p>Here's the workflow to test that everything is working:</p> <ol> <li>Update your config.yml (in app/config) to include Doctrine configuration parameters</li> <li>Open a prompt and go to the root folder of the Symfony distribution (where you see the app, src, vendor and web folders)</li> <li>Run <code>php app/console doctrine:database:create</code> to create the database in MySQL</li> <li>Run <code>php app/console doctrine:schema:create</code> to create the database structure</li> <li>Check in MySQL that the database and the structure have been created correctly</li> </ol> <p>Hope this help.</p> <p>Regards,<br> Matt</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload