gpt4 book ai didi

mysql - Laravel 5,更新 1 行,但影响多行。为什么?

转载 作者:行者123 更新时间:2023-11-29 21:58:23 25 4
gpt4 key购买 nike

更新前。

mysql> select parcel_id,type, status ,accepted_at,accepted_user,submitted_at,submitted_user, updated_at from parcel_deliveries;
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| parcel_id | type | status | accepted_at | accepted_user | submitted_at | submitted_user | updated_at |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| RI013502995TH | 1 | 1 | 2015-09-29 15:01:44 | hnong | 2015-09-29 17:19:56 | hnong | 2015-09-30 16:50:11 |
| EN064142823TH | 1 | 1 | 2015-10-02 16:17:39 | hnong | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:12:39 |
| EN064142823TH | 2 | 1 | 2015-10-02 16:39:43 | hnong1 | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:12:39 |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+

一组 3 行(0.00 秒)

更新记录,我打算只更新 1 行(parcel_id = EN064142823TH,type=2)

$a = App\Parcel_delivery::where('parcel_id', 'EN064142823TH')
->where('type', '=', 2)
->where('postal_code', '10170')
->orderBy('created_at', 'desc')->first();

=> App\Parcel_delivery {#829
parcel_id: "EN064142823TH",
type: 2,
status: 1,
accepted_at: "2015-10-02 16:39:43",
accepted_user: "hnong1",
submitted_at: "2015-10-02 16:48:24",
submitted_user: "hnong",
destination_id: null,
person_type: null,
signature: null,
comment: "",
run_no: null,
}
>>> $a->status = 5;
=> 5
>>> $a->save(); => true

更新后。

mysql> select parcel_id,type, status ,accepted_at,accepted_user,submitted_at,submitted_user, updated_at from parcel_deliveries;
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| parcel_id | type | status | accepted_at | accepted_user | submitted_at | submitted_user | updated_at |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+
| RI013502995TH | 1 | 1 | 2015-09-29 15:01:44 | hnong | 2015-09-29 17:19:56 | hnong | 2015-09-30 16:50:11 |
| EN064142823TH | 1 | 5 | 2015-10-02 16:17:39 | hnong | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:14:43 |
| EN064142823TH | 2 | 5 | 2015-10-02 16:39:43 | hnong1 | 2015-10-02 16:48:24 | hnong | 2015-10-02 17:14:43 |
+---------------+------+--------+---------------------+---------------+---------------------+----------------+---------------------+

一组 3 行(0.00 秒)

我不知道为什么另一条记录也被更新(parcel_id = EN064142823TH,type=1)。

请提出建议。

最佳答案

您的表缺少唯一的主键,因此 Eloquent 无法区分一条记录与另一条记录,因此无法应用更新。在你的表中添加一个自动增量id主键字段,我想这个问题将会得到解决。

关于mysql - Laravel 5,更新 1 行,但影响多行。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32905061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com