Home > Back-end >  How to delete Entity from the database in Symfony
How to delete Entity from the database in Symfony

Time:12-02

I am using Symfony 6 and I created an entity using the command "php bin/console make:entity". But it was a test, so now I want to remove completely the entity (PHP class SQL table).

How can I delete it properly ? Even if it was in production env. Because I read that we shouldn't run "php bin/console d:s:u --force" in production env.

Thanks

CodePudding user response:

Updating, adding or removing entities can be performed like this:

  1. Delete the entity file in src/entity.
  2. Run the command php bin/console doctrine:migrations:diff --allow-empty-diff. (this will create the migration file in /migrations, look at this and you will see the sql commands)
  3. Then run the command php bin/console doctrine:migrations:migrate --allow-no-migration. (this will run the migration file and update your db)
  4. (optional) Clean up with php bin/console cache:clear.

I have added --allow-empty-diff and --allow-no-migration options, so if you are going to use a deployment script (for production), then these can be run all the time even if there are no differences or updates to your entities and no errors will be thrown.

  • Related