【问题标题】:Laravel migration infinite loopLaravel 迁移无限循环
【发布时间】:2018-11-21 07:51:42
【问题描述】:

我在下面有一个自定义迁移命令

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...

我该如何解决这个问题?

【问题讨论】:

  • 你运行的是什么 laravel 版本?

标签: laravel database-migration


【解决方案1】:

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

$this->call('migrate');

如果你打算调用父类的行为,那么你真正想要的是

parent::handle();

奖金

这是extending custom migration commands的教程。

【讨论】:

  • 如果使用parent::handle(),如何指定迁移文件夹
  • 如何使用parent::handle()设置--path和其他选项?
猜你喜欢
  • 2014-12-21
  • 2018-03-20
  • 2020-03-02
  • 2020-12-13
  • 2014-04-27
  • 1970-01-01
  • 2018-03-31
  • 1970-01-01
  • 2020-07-11
相关资源
最近更新 更多