Yii Migrate --Interactive=False - How To Force Migration

Hi All,

I’m using Capistrano 3 to handle deployment for my Yii2 Advanced App, and what I’m trying to figure out is the best way to handle database migrations during deployment. Git will take care of tracking the new Yii migration files as their created, and then in Capistrano, I have an execute command to run “php yii migrate” within the deployment directory during the deployment process.

This all works properly, the "php yii migrate" command is running, however when Yii starts to process the migration file(s), the console log displays the standard "Do you want to perform these migrations?" question, as the response to running the migrate command. The challenge arises in that the Capistrano deploy process is already running, so the Yii migration question is not answerable at the time the "php yii migrate" command is getting run.

So, my questions are …

  1. Is there a way to force Yii to do the migrations without having to confirm the migrations by typing yes and then pressing enter? I see some information online about passing an --interactive=false param, such as “php yii migrate --interactive=false”, but it looks like this technique was for Yii1 and doesn’t seem to work as I would expect in Yii2. Does anyone know if this is possible in Yii2?

  2. Is there a better way to be doing this? I can see how it may be dangerous to force a database migration on deployment, but I plan to minimize this risk by asking/confirming with the deploying user before they start the deployment if they want to migrate the database. In other words, if the deploying user doesn’t confirm the migration in the console before deploying starts, the database would not be migrated. Therefore, I’m asking the same question that Yii does to confirm that a database migration is desired. I’m just asking the question at a different time from when the actual migrate command is run. I ask the question about performing a database migration before the deploy starts, rather than when Yii is actually getting ready to process the migration.

  3. If there’s no way to force yii to migrate in one shell command, does anyone know if there is a way to capture the yii output and print the question to the console so it can be answered? Basically, Capistrano would run the migrate command, and then when Yii responds with the question about confirming the migration, Capistrano would puts/echo/print the question in a manner that still allows the deploying user to answer the question from the Capistrano process. This is more of a Capistrano, shell scripts question, but it can’t hurt to ask :)

  4. Is there something I’m missing, or does anyone have a better approach for having Capistrano 3 migrate the Yii2 database during deployment?


How do y’all prefer to handle Yii2 database migrations with an automated deployment script such as Capistrano?

Thanks so much!

While I’m still interested in hearing what the community knows that I don’t … I was able to solve my challenge by “piping” the response into the migrate command.

Here’s some good info on piping:


And here’s the command that I ended up running in Capistrano 3 to handle the Yii2 database migration:

on roles(:web) do

	within release_path do

		execute 'echo', ' -e "yes" | php yii migrate'




  1. Yes. It’s --interactive=0.