gpt4 book ai didi

mysql - 无法使用 Rails 5.0.1 和 MySQL 更新 bool 列

转载 作者:行者123 更新时间:2023-11-29 17:08:45 42 4
gpt4 key购买 nike

我有一个模型Diary,其中有列is_draft( bool 值,null:false)。我将其设置为枚举范围,例如 is_draft: { Draft: true,published: false }

当我在 Rails 控制台中执行此操作时,

Diary.last.update!(is_draft: false)

它创建一个像这样的查询,但失败了:

UPDATE `diaries` SET `is_draft` = NULL, `updated_at` = '2018-08-22 16:39:17' WHERE `diaries`.`id` = 66

ActiveRecord::StatementInvalid: Mysql2::Error: Column 'is_draft' cannot be null

另一方面,这成功了。

Diary.last.update!(is_draft: true)

如何将其更新为 false?

最佳答案

在您的测试中,您尝试更新 false 值还是 true 值?

从真实出发,尝试一下:

Diary.last.update_attributes(is_draft: false)

关于mysql - 无法使用 Rails 5.0.1 和 MySQL 更新 bool 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51962015/

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