我在 Rails 应用程序中有一个表(在 schema.rb 中)如下所示:
create_table "users", :force => true do |t|
t.string "name", :null=>false
t.string "address", :null=>false
end
我想编写一个 Rails 迁移以允许地址字段为空。即迁移后,表如下所示:
create_table "users", :force => true do |t|
t.string "name", :null=>false
t.string "address"
end
我需要做什么才能消除限制?
在Rails 4+中为了删除非空约束,您可以使用change_column_null http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column_null:
change_column_null :users, :address, true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)