Laravel命令迁移表而不复制所有记录

时间:2019-03-20 18:18:18

标签: database laravel laravel-5 database-migration

我创建了一种将数据从一个DB迁移到另一个DB的方法。问题出在大约15k行而Laravel仅复制12k或12.5k或13k的情况下。每次都在范围内。就像它以某种方式超时但没有错误。

我所有的行都设置为可为空,并且我确实设置了上限以防万一。

public function handle()
    {

        ini_set('memory_limit', '-1');
        ini_set('max_execution_time', 300); //300 seconds = 5 minutes
        ini_set('max_execution_time', 0); // for infinite time of execution
        set_time_limit(555550);


        $this->info('Starting Import Report');
        $oldReports = DB::connection('old')->select("SELECT * FROM `report` ORDER by ReportID");

        //dd(count($oldReports));
        $i = 1;
        foreach ($oldReports as $oldReport) {

            $this->info('#'  . $i . ' --- Report ID: '. $oldReport->ReportID);

            $report = new Report();
            $report->id = $oldReport->ReportID;
            $report->file_id = $oldReport->FileID;
            $report->report = $oldReport->Report;
            $report->type_of_report = $oldReport->TypeOfReport;
            $report->report_date = $oldReport->ReportDate;


            $report->created_at = \Carbon\Carbon::now();
            $report->updated_at = null;

            $report->save();

            $i++;

        }


        $this->info('Completed Import Report');
    }

0 个答案:

没有答案