gpt4 book ai didi

mysql - ActiveRecord::Rollback 似乎没有进行事务回滚

转载 作者:行者123 更新时间:2023-11-29 20:48:03 26 4
gpt4 key购买 nike

有一天,我注意到我的事务不接受 ActiveRecord::Rollback。我有一个这样的例子:

示例

ActiveRecord::Base.transaction do
puts @shipment_list.status
@shipment_list.update(shipment_list_params)
raise ActiveRecord::Rollback
end
puts @shipment_list.status

结果

CACHE (0.0ms)  SELECT  `shipment_lists`.* FROM `shipment_lists`  WHERE `shipment_lists`.`id` = 24121  ORDER BY created_at DESC LIMIT 1  [["id", "24121"]]
(0.2ms) BEGIN
reserve
(1.3ms) SELECT MAX(`audits`.`version`) AS max_id FROM `audits` WHERE `audits`.`auditable_id` = 24121 AND `audits`.`auditable_type` = 'ShipmentList'
SQL (160.5ms) INSERT INTO `audits` (`action`, `auditable_id`, `auditable_type`, `audited_changes`, `created_at`, `remote_address`, `request_uuid`, `user_id`, `user_type`, `version`) VALUES ('update', 24121, 'ShipmentList', '---\nstatus:\n- reserve\n- 2\n', '2016-07-10 12:01:55', '127.0.0.1', 'efc5b6e7-c3f9-4b4a-a0fd-67651b2eeb20', 18, 'User', 19)
SQL (0.3ms) UPDATE `shipment_lists` SET `status` = 2, `updated_at` = '2016-07-10 12:01:55' WHERE `shipment_lists`.`id` = 24121
(0.2ms) ROLLBACK
bill

哪里错了?我真的遇到麻烦了。

最佳答案

实际上这个问题是由 myISAM mysql schema 引起的。不允许事务回滚。

关于mysql - ActiveRecord::Rollback 似乎没有进行事务回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38291749/

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