SQLSTATE[23000]
Posted
技术标签:
【中文标题】SQLSTATE[23000]【英文标题】: 【发布时间】:2016-03-03 04:36:39 【问题描述】:我对 laravel 的 phpmyadmin 有问题 我想通过控制器更新数据库视图中的数据,但发生错误
// save all seats
foreach ($request->all() as $key => $param)
if ($key === '_token') continue;
$data = explode('-', $key);
$bs = new BookedSeat();
$bs->booking_id = $booking->id;
$bs->day_id = str_replace('c', '', $data[0]);
$bs->table_id = str_replace('t', '', $data[1]);
$bs->number = 0;
$bs->status = 'requested';
$bs->save();
its an error when i try update data
its my db
【问题讨论】:
请分享你的插入数据代码,需要插入day_id
外键
【参考方案1】:
更新
// save all seats
foreach ($request->all() as $key => $param)
if ($key === '_token') continue;
$data = explode('-', $key);
$bs = new BookedSeat();
$bs->booking_id = $booking->id;
$day = DB::table('days')->where('name',$data[0])->get();
$bs->day_id = $day->id;
$bs->table_id = str_replace('t', '', $data[1]);
$bs->number = 0;
$bs->status = 'requested';
$bs->save();
【讨论】:
嗨,朋友。书的 id 或 id 是书以上是关于SQLSTATE[23000]的主要内容,如果未能解决你的问题,请参考以下文章
SQLSTATE [23000]:违反完整性约束:4025 CONSTRAINT
SQLSTATE[23000]:Laravel 中的完整性约束违规
SQLSTATE [23000]:完整性约束违规:1048 laravel 5.7