i am getting this error
SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into day_schedules
(updated_at
, created_at
) values (2017-03-13 06:56:39, 2017-03-13 06:56:39))
Controller:
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'])]);
}
}
}
Table:
CREATE TABLE day_schedules
( id
INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, user_id
INT(10) UNSIGNED NOT NULL, event_id
INT(10) UNSIGNED NOT NULL, day_id
INT(10) UNSIGNED NOT NULL, time_s
VARCHAR(50) NOT NULL, time_e
VARCHAR(50) NOT NULL, sch_title
LONGTEXT NOT NULL, sch_desc
LONGTEXT NOT NULL, created_at
TIMESTAMP NULL DEFAULT NULL, updated_at
TIMESTAMP NULL DEFAULT NULL, PRIMARY KEY (id
), INDEX FK_dayschedules_users
(user_id
), INDEX FK_dayschedules_events
(event_id
), INDEX FK_dayschedules_days
(day_id
), CONSTRAINT FK_dayschedules_days
FOREIGN KEY (day_id
) REFERENCES days
(id
) ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT FK_dayschedules_events
FOREIGN KEY (event_id
) REFERENCES events
(id
) ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT FK_dayschedules_users
FOREIGN KEY (user_id
) REFERENCES users
(id
) ON UPDATE CASCADE ON DELETE CASCADE )
via Jamal Ahmad