获取错误在Laravel 5.4中没有默认值

时间:2017-03-13 07:09:23

标签: mysql laravel laravel-5 laravel-5.4

我收到此错误:

  

SQLSTATE [HY000]:常规错误:1364字段'user_id'没有默认值(SQL:插入git clone ../some\ folder\ with\ spaces/day_schedulesupdated_at)值(2017- 03-13 06:56:39,2017-03-13 06:56:39))

控制器:

created_at

表:

if(isset($eventId)){
    //dd($eventId);
    for($i=0; $i<$days;$i++){
        $request->request->add(['user_id'=>$userid]);
        $request->request->add(['event_id'=>$eventId]);
        $dayPostData = Day::create($request->except(['_token', 'submit', 'title','description','firstDate','secondDate', 'days','location','tags','event-img','event_img','sch-e','sch-s','sch-title','sch-desc']));
        $dayId=$dayPostData->id;
        //dd($dayId);
        $countSchedules=count($arr[$i]);
        //$scheduleData = DaySchedule::firstOrNew(['user_id' => Auth::user()->id]);
        for ($j=0;  $j < $countSchedules; $j++){
            //dd($eventId);
            $request->request->add(['user_id'=>$userid]);
            $request->request->add(['event_id'=>$eventId]);
            $request->request->add(['day_id'=>$dayId]);
            $scheduleData = DaySchedule::create([$request->except(['_token', 'submit', 'title','description','firstDate','secondDate' ,'days','location','tags','event-img','event_img'])]);

        }

    }

}

1 个答案:

答案 0 :(得分:0)

MySQL最有可能处于STRICT模式。尝试运行SET GLOBAL sql_mode =&#39;&#39;或编辑你的my.cnf以确保你没有设置STRICT_ALL_TABLES等。

在你的phpmyadmin中运行你的数据库中的SELECT @sql_mode sql check sql_mode