Very simple thing I want to do, however I fail to find a solution.
I have started to develop my app with Symfony4 bundled with Doctrine. At the beginning I have designed database model but during development I have realized original solution is wrong way for what I want to do. Right now, I want to remove an attribute from entity. In plain SQL I would do ALTER TABLE table DROP COLUMN column
then recreate it again with new parameters. However this solution gave me an error in Doctrine, so I have changed PHP model as well. Again, another error. Okay, so this does not look like the way I want to go.
Is there any solution to my problem, except digging too deep in Doctrine? Best would be something simple like described in the SQL command above?
When it comes to doctrine with symfony you should forget about tables, columns etc.. and start thinking with objects (otherwise there's no point in using doctrine for abstraction). For your problem you should simply remove the attribute in your entity.
Then You should use :
php bin/console doctrine:migrations:diff
Which will generate a migration file under the /migrations folder. This file will contain the SQL that doctrine will execute. It allows you to verify if the query is what you expect, if not you can directly modify it in that file or adapt your entity and generate a new migration file.
When you are happy with it, you can execute it with :
php bin/console doctrine:migrations:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With