Rails迁移:消除约束 [英] Rails Migration: Remove constraint
本文介绍了Rails迁移:消除约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Rails应用程序中有一个表(在schema.rb中)如下:
I have a table in a Rails application which (in schema.rb) looks like:
create_table "users", :force => true do |t|
t.string "name", :null=>false
t.string "address", :null=>false
end
我想编写一个rails迁移,以允许地址字段为空。即,迁移后,该表如下所示:
I would like to write a rails migration to allow nulls for the address field. i.e. after the migration the table looks like this:
create_table "users", :force => true do |t|
t.string "name", :null=>false
t.string "address"
end
我需要怎么做才能消除约束?
What do I need to do to remove the constraint?
推荐答案
不确定可以拨打 t.address
吗?无论如何...我会这样使用 change_column
Not sure you can call t.address
? Anyway... I would use change_column
like so
change_column :users, :address, :string, :null => true
文档...
http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/change_column
这篇关于Rails迁移:消除约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文