How do you delete the `reference` column in rails 3.1?

I created a table with a references column in an earlier migration, and now I would like to leave it. I know that I can make a remove_column call for the generated name, but is there a way to remove it using the table name instead?

remove_references :blah, :users instead of remove_column :blah, :user_id

+4
source share
2 answers

The method, which is supposedly called remove_references , you guessed it. It needs only one parameter, the same as references , one parameter is required:

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) 
+4
source

There is no special method for this. When you think about it, it makes sense, since the references method does not actually create an external constraint in db, which means that this generated column is not special.

Refresh

As @Zabba noted, there is a remove_references method. I have never seen this used in practice, but its description sounds correct.

+3
source

All Articles