Doctrine Migrations in new DB setup Doctrine Migrations in new DB setup symfony symfony

Doctrine Migrations in new DB setup


Just after fresh install to fill current schema use this commands:

  1. Create new empty chema of current version

    ./bin/console doctrine:schema:create

  2. Fill out the migration records with the current version (without actually run the migrations - schema already has current version after first command)

    ./bin/console doctrine:migrations:version --add --all

This command adds records of the migrations and doctrine:migrations:status will show you that there is no migrations need for the current verions.

Thats all!


As mentioned in my comment, I've successfully created a blank database schema just by using Doctrine migrations. I believe it's necessary to create the empty database first (php app/console doctrine:database:create) and then run the migrations task.

The only potential issue I can think of is that any base data that your app requires to function will either need to be in the migrations files or will need to be inserted separately.

As an aside, running the all the migrations in one go has picked up a couple of small errors that I'd missed when just executing one at a time.


I think you can pick the very first migration class, copy it and rename with just one second before.

So, if your first class is 2016060712284351 you should create a new class called 2016060712284350. This way it is executed just before the real migrations.

In this newly created class you setup your database creating all needed tables. This way, when you run migrations the first thing is done is to create the database with all the tables and then the real migrations are run.

Anyway I'm not sure this is the real way to proceed.Migrations are needed to update the database schema, but if you are creating a new database for each user, each of the new users will have the new schema as per entities mapping. So a migration is not needed.

You need to run migration only for OLD USERS' DATABASES, am I right?