gpt4 book ai didi

ruby-on-rails-4 - 轨道 4 : Remove not null constraint from table column with migration?

转载 作者:行者123 更新时间:2023-12-03 06:59:13 24 4
gpt4 key购买 nike

给定以下schema.rb:

  create_table "people", force: true do |t|
t.string "name", null: false
t.integer "age"
t.integer "height"
t.string "email"
t.boolean "married", default: false
t.text "bio"
t.integer "fav_number"
t.decimal "lucky_num", precision: 2, scale: 2
t.datetime "birthday"
t.datetime "created_at"
t.datetime "updated_at"
end

我想删除 name 默认值 null: false。我尝试使用 change_column_default 运行单独的迁移,但这对 schema.rb 没有影响。有什么建议吗?

最佳答案

来自docs :

  def up
change_column_default :table_name, :status, 0
end

def down
change_column_default :table_name, :status, nil
end

关于ruby-on-rails-4 - 轨道 4 : Remove not null constraint from table column with migration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23098047/

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