关于使用laravel模型更新某字段失败的问题
今天在一个数据表中新增一个字段,然后使用model模型更改该字段值得时候提示 Column not fount: 1054 Unknown column ‘yun_mch’ in ‘field list’, 能确保该字段确实存于表中; 是不是模型有缓存,出现这种情况该你们是如何处理的
$data = [
'mch_id' => $_info['mch_id'],
'wechat_appid' => $_info['wechat_appid'],
'subscribe_appid' => $_info['appid'],
'is_entrust' => $_info['is_entrust'],
'surport_alipay' => $_info['surport_alipay'],
'remark' => $_info['mch_remark'],
'status' => $_info['status'],
'check_time' => $_info['mch_check_time'],
'create_time' => date("Y-m-d H:i:s"),
'ali_fee' => $_info['ali_fee'],
'wx_fee' => $_info['wx_fee'],
'transfer_type' => $_info['transfer_type'],
'service_id' => $_info['service_id'],
'ali_mch_id' => $_info['ali_mch_id'],
'wx_mch_id' => $_info['wx_mch_id'],
'yun_mch' => $_info['yun_mch']
];
public function updateLepassMchByShopId(int $shopId, array $data)
{
$lepassMch = LePassMchModel::where('shop_id', $shopId)
->first(['shop_id']);
if (empty($lepassMch)) {
throw new ApiException('shop_id不存在');
}
$shopId = $lepassMch->shop_id;
$lepassMch->setRawAttributes($data);
$ret = $lepassMch->save();
if (!$ret) {
throw new ApiException('更新失败');
}
$this->delRedisCache(KeyConst::LePassMch, $shopId);
}
原因是:model的数据库改变了,我测试验证走的都是旧库; 备注一下,以后有类似问题先确定库,再确定表;
推荐文章: