symfonydoctrinesymfony4doctrine-migrations

How to prevent doctrine from generating unneeded migrations?


I use Symfony 4.2 and following database-first approach and have auto-generated entities; But then I need to do some changes in field definitions in entities but I don't want to affect the database structure. Everything works well but if I try to create a migration, doctrine includes all the differences in migrations, and I find no way to prevent this behaviour. I've tried schema_filter: ~^migration_versions$~ but somehow it doesn't help.

So the questions:

  1. Is it a normal application state on prod when column definitions slightly differ in database and entities?

  2. How can I say to doctrine to ignore differences in some tables when creating migrations?


Solution

  • When you run bin/console doctrine:migrations:diff it will generate a file in your src\Migrations\ directory. You can edit the generated file to remove whatever you don't want to change before you run bin/console doctrine:migrations:migrate.

    I don't suggest doing this on a production server though, and especially if you do so then you should certainly have a backup of your database.