Doctrine migrations: How to avoid SQL errors in the postUp step? Doctrine migrations: How to avoid SQL errors in the postUp step? symfony symfony

Doctrine migrations: How to avoid SQL errors in the postUp step?


The scenario you describe perfectly shows that it is not possible (in general) to use entities in Doctrine Migrations.

So I'm afraid the only way to make this work in a robust fashion is to descend to the DBAL level:

public function postUp(...) {    $this->connection->insert('entities', [        'col1' => 'value1',        'col2' => 'value2'    ]);}

By using the DBAL query the columns to be used are supplied directly instead of indirectly via the entity that is defined by the application code, which does not need to be in sync with the current table structure.

See also section 4.2 of the "How to work with Doctrine migrations in Symfony" post, which also describes this issue with using entities in Doctrine Migrations, especially the following quote:

don't use entities within migrations, you must not rely on the entity (PHP) code, but on the database only!