sajad torkamani

What does it do?

If you run:

bin/console doctrine:schema:update --dump-sql

Doctrine will compare your Doctrine entity metadata (attributes, annotations, etc) with the current database schema (tables, columns, indexes, constraints, etc) and print out what SQL would need to be executed to align your database schema with your Doctrine entities. It doesn’t execute that SQL – it just prints it out.

Why would I use it in practice?

In practice, you typically use Doctrine migrations to make changes to your database. The bin/console doctrine:schema:update --dump-sql is useful only to do quick sanity checks to ensure your underyling database schema is aligned with your Doctrine entities.

Ideally, running the bin/console doctrine:schema:update --dump-sql command should return nothing because your database schema and Doctrine entities should always be aligned. But in case it does print something, you can create a migration file to add the SQL it outputs.

The --force flag

If you want to actually run the SQL that the doctrine:schema:update --dump-sql command outputs, you can use the --force flag to run the SQL needed to align your database schema with your Doctrine entities:

doctrine:schema:update --force

As mentioned earlier, you will typically use migrations to update your database schema. The --force flag might be useful for quick prototyping or throwaway databases.

Tagged: Doctrine