How do you drop a `references` column in rails 3.1?
I've created a table开发者_C百科 with a references
column in an earlier migration and now I would like to drop it. I know I can do a call to remove_column
on the generated name, but is there a way to remove it using the the table name instead?
remove_references :blah, :users
instead of remove_column :blah, :user_id
There is the method aptly named remove_references, as you guessed. It only needs one parameter, same as references
needs one parameter too:
From the API documentation:
remove_references(*args)
#Removes a reference. Optionally removes a type column. remove_references and
#remove_belongs_to are acceptable.
Examples
t.remove_references(:goat)
t.remove_references(:goat, :polymorphic => true)
t.remove_belongs_to(:goat)
There is no special method to do so. When you come to think about this it makes perfect sense, since the references
method doesn't actually create a foreign constraint in the db, meaning that this generated column isn't special at all.
Update
As @Zabba noted there seems to be a remove_references method. I've never seen it used in practice, but its description sounds about right.
精彩评论