How do I generate an initial/base migration for existing Symfony+Doctrine application?

Viewed 7511

If I already use migrations, I can easily generate incremental one using: app/console doctrine:migrations:diff.

But assume I have an existing application that does not use migrations yet. doctrine:migrations:diff will just generate a diff between the current database schema and doctrine entities. The problem is I need to have an initial/first migration consisting of CREATE TABLE for every entity created up to this point. My current workaround is to create an empty database, switch credentials in parameters.yml, and run doctrine:migrations:diff then.

I don't like this solution - is there a better one?

3 Answers

And what about a little :

bin/console doctrine:migrations:diff --from-empty-schema

With the flag --from-empty-schema it will do exactly what you're asking for.

After that you can (must) manually add an entry in the doctrine_migration_versions table if the DB is already set up and you want to (have to) run /bin/console doctrine:migrations:migrate. Like that (screenshot from adminer):

enter image description here

Related