Scroll down to the script below, click on any sentence (including terminal blocks!) to jump to that spot in the video!Cool, got it! Show me the script!
We described the
genus table to Doctrine via annotations, but this table doesn't
exist yet. No worries - Doctrine can create it for us!
And actually, we don't even have a database yet. Doctrine can also handle this. Head to the terminal use the console to run:
But wait! Can Doctrine do this yet? We haven't told it anything about the database: not the name we want, the user or the password.
Where do we do that? The same place that everything, meaning all services are
app/config/config.yml. Scroll down to the
|... lines 1 - 43|
|# Doctrine Configuration|
|# if using pdo_sqlite as your database driver:|
|# 1. add the path in parameters.yml|
|# e.g. database_path: "%kernel.root_dir%/data/data.db3"|
|# 2. Uncomment database_path in parameters.yml.dist|
|# 3. Uncomment next line:|
|# path: "%database_path%"|
|... lines 60 - 72|
Ah, this is what tells Doctrine all about your database connection.
But, the information is not hardcoded here - these are references to parameters
that are defined in
|... lines 1 - 3|
|# You should uncomment this if you want use pdo_sqlite|
|# database_path: "%kernel.root_dir%/data.db3"|
|... lines 12 - 15|
aqua_note and on my super-secure local machine,
the database user is
root with no password.
Find out more about these parameters in our Symfony Fundamentals Series.
Back to the terminal! Now hit enter on the command:
Database created. To create the table, run:
./bin/console doctrine:schema:update --dump-sql
This looks great -
CREATE TABLE genus with the two columns. But this didn't execute
the query yet - the
--dump-sql option is used to preview the query if you're curious.
Replace it with
./bin/console doctrine:schema:update --force
So hey guys, this is really cool - we can be totally lazy and let Doctrine do all
the heavy database-lifting for us. This
doctrine:schema:update command is actually
more powerful than it looks - it's going to "wow" us in a few minutes.
But first, let's learn how to insert data into the new table.