LoginSignup
1
0

More than 3 years have passed since last update.

Laravelのマイグレーションで「Application In Production!」が表示されたときの対処法

Last updated at Posted at 2020-07-06

はじめに

本番環境でマイグレーションを実行したら、以下のメッセージが表示されて、マイグレーションが実行されなかった。

**************************************
*     Application In Production!     *
**************************************

環境

$ php artisan -V
Laravel Framework 5.8.29

メッセージが表示された理由

productionでマイグレーションを実行する場合、以下のメソッドで環境のチェックが行われ、productionの場合はメッセージが表示されます、

/vendor/laravel/framework/src/Illuminate/Console/ConfirmableTrait.php
<?php

namespace Illuminate\Console;

use Closure;

trait ConfirmableTrait
{
    /**
     * Confirm before proceeding with the action.
     *
     * This method only asks for confirmation in production.
     *
     * @param  string  $warning
     * @param  \Closure|bool|null  $callback
     * @return bool
     */
    public function confirmToProceed($warning = 'Application In Production!', $callback = null)
    {
        $callback = is_null($callback) ? $this->getDefaultConfirmCallback() : $callback;

        $shouldConfirm = $callback instanceof Closure ? call_user_func($callback) : $callback;

        if ($shouldConfirm) {
            if ($this->hasOption('force') && $this->option('force')) {
                return true;
            }

            $this->alert($warning);

            $confirmed = $this->confirm('Do you really wish to run this command?');

            if (! $confirmed) {
                $this->comment('Command Cancelled!');

                return false;
            }
        }

        return true;
    }

    /**
     * Get the default confirmation callback.
     *
     * @return \Closure
     */
    protected function getDefaultConfirmCallback()
    {
        return function () {
            return $this->getLaravel()->environment() === 'production';
        };
    }
}

対処法

--forceオプションをつけて、マイグレーションを実行すればOK

$ php artisan migrate --force

余談

今回、事象が発生したのは、AWS Lambdaにてカスタムランタイム(brefを使用)上でLaravelを動かしている環境でした。
そのため、単に--forceをつけるだけだと、コマンドエラーとなり、以下のようにダブルコーテーションで囲むことで無事にマイグレーションが実行できました。

$  AWS_PROFILE=【profile name】 vendor/bin/bref cli --region ap-northeast-1 【function name】 "migrate --force"
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0