gpt4 book ai didi

mysql - 编写将日期时间变为 null :false to true 的数据库迁移

转载 作者:行者123 更新时间:2023-11-29 14:13:30 26 4
gpt4 key购买 nike

我正在尝试编写一个数据库迁移,将连接表中的日期时间字段从 null 更改为 true,但有些东西无法正常工作。这是我的代码:

class ChangeDateColumnsInCirclesUsers < ActiveRecord::Migration
def change
change_column :circles_users, :created_at, :datetime, :null => true
change_column :circles_users, :updated_at, :datetime, :null => true
end
end

这不起作用。关于如何将这些 null 值设置为 true 而不是 false 有什么想法吗?

最佳答案

试试这个

change_column :table_name, :created_at, :datetime, :null => true, :default => nil

并运行迁移

关于mysql - 编写将日期时间变为 null :false to true 的数据库迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13082522/

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