php bin/console doctrine:schema:update
Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata
Usage
doctrine:schema:update [--em EM] [--complete] [--dump-sql] [-f|--force]
Options
--em Name of the entity manager to operate on
--complete This option is a no-op and will be removed in 4.0
--dump-sql Dumps the generated SQL statements to the screen (does not execute them).
-f, --force Causes the generated SQL statements to be physically executed against your database.
Help
The doctrine:schema:update command generates the SQL needed to
synchronize the database schema with the current mapping metadata of the
default entity manager.
For example, if you add metadata for a new column to an entity, this command
would generate and output the SQL needed to add the new column to the database:
doctrine:schema:update --dump-sql
Alternatively, you can execute the generated queries:
doctrine:schema:update --force
If both options are specified, the queries are output and then executed:
doctrine:schema:update --dump-sql --force
Finally, be aware that this task will drop all database assets (e.g. tables,
etc) that are *not* described by the current metadata. In other words, without
this option, this task leaves untouched any "extra" tables that exist in the
database, but which aren't described by any metadata.
Hint: If you have a database with tables that should not be managed
by the ORM, you can use a DBAL functionality to filter the tables and sequences down
on a global level:
$config->setSchemaAssetsFilter(function (string|AbstractAsset $assetName): bool {
if ($assetName instanceof AbstractAsset) {
$assetName = $assetName->getName();
}
return !str_starts_with($assetName, 'audit_');
});