Symfony doctrine remove column from entity table

I had to dig and dig and dig to find this. Explanation here.

php bin/console doctrine:migrations:diff

instead of making a migration, this command makes the migration file for you. Then you can run this command

php bin/console doctrine:migrations:migrate

To actually change the table.

3 replies on “Symfony doctrine remove column from entity table”

It’s dangerous to generate automatically. If you made changes in the previous migrations, that aren’t supported natively by doctrine (like default values or some custom SQL generated via PHP), then the `migrations:diff` (or `make:migration`) will try to restore previous state that might not make sense and silently revert your custom code.
Don’t trust doctrine auto-generation; always verify that what was generated makes sense to you.
It’s just a helper, not an automatic tool for avoiding to know SQL.
Also i think I read that it might be removed in the future.

Doctrine (and symfony bundle for doctrine) have a command to update DB schema without any migrations.

This is may be useful while developing, but not in production environment. (link for outdated symfony version, because it is dropped from newer versions – may be related to dangerous behavior)

Thanks I started this thing way back in version 2. Didn’t work on it for a year + came back it was version 4. Got started and now it was version 5 time. This has been a slow learning experience. I spend a lot of time on github digging into the symfony source code just to find out how things work because so much is not in the docs for 5 and some of it causes errors. It was using smarty back when I started now it is twig.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.