Laravel迁移无限循环

时间:2018-06-12 02:03:47

标签: laravel database-migration

我在

下面有一个自定义迁移命令
use Illuminate\Database\Console\Migrations\MigrateCommand as BaseMigrateCommand;

class MigrateAllCustomersCommand extends BaseMigrateCommand
{
    private $count = 0;
    public function __construct(Migrator $migrator)
    {
       parent::__construct($migrator);
    }

    public function handle()
    {
        $this->count += 1;
        printf("%d,",$this->count);
        $this->call('migrate');
    }
}

php artisan migrate无限运行,如以下输出所示:1,2,3,...,10000...

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

这会使您的迁移被递归调用,从而导致无限循环。

$this->call('migrate');

如果您打算调用父类的行为,那么您实际想要的是

parent::handle();

加成

这是关于extending custom migration commands的教程。

相关问题