J. Bruni
J. Bruni

Reputation: 20492

Is there a "generate-migrations-db" equivalent in Symfony 2 / Doctrine 2?

Here is the legacy documentation explaining what "generate-migrations-db" does:

http://symfony.com/legacy/doc/doctrine/1_2/en/07-Migrations

It says

Generate migration classes from existing database connections (doctrine-generate-migrations-db, doctrine-gen-migrations-from-db)

Also:

Generating Migrations

Doctrine offers the ability to generate sets of migration classes for existing databases or existing models as well as generating blank migration classes for you to fill in with the code to make your schema changes.

From Database

If you have an existing database you can build a set of migration classes that will re-create your database by running the following command.

$ ./symfony doctrine:generate-migrations-db

In other words: it takes the schema from the database and generates a migration that performs that schema creation. No entities, no classes, no mappings are used in this process. It just takes a DB and builds a migration class.

We do not have generate-migrations-db anymore. Do we have something that performs that task? I couldn't find. If it was replaced by some other command, please let me know. If it was just removed, please let know.

Upvotes: 3

Views: 3602

Answers (2)

Sam
Sam

Reputation: 6610

I'm not aware of a command in Doctrine or the Migrations Bundle that creates migration files for an existing database.

So here's how I did it instead:

  1. Install DoctrineMigrationsBundle
  2. Create a new blank database
  3. Update your config or parameters to point to this blank database rather than to your "real" one
  4. Run php app/console doctrine:migrations:diff. This will create a migrations file that creates your database tables etc from scratch
  5. Change back your config/parameters

Hope this is helpful.

Upvotes: 6

Emii Khaos
Emii Khaos

Reputation: 10085

Take a look at the DoctrineMigrationsBundle, which can generate migration classes with sql statements for migration.

Upvotes: 1

Related Questions