Hello guys,
I’ve been using Ruby for a long time now and a simple doubt always make me wonder…
Why do i need do specify the column type when removing a column?
I always do the following when removing a column:
remove_column :table, :column, :type
But the thing is…isn’t the column name unique? Or can i have multiple columns with same name but different types?
Sorry if it’s a stupid question tho
Thanks
Jason_FB
(Jason FB)
November 14, 2016, 9:11pm
2
I think that only happens when you use def change so that when you reverse the migration it knows how to add the column back.
I think if you do the old migration style of def up / def down you don’t need to specify the column type in your remove_column
tjschuck
(T.J. Schuck)
November 14, 2016, 9:12pm
3
Hi Gabriel,
The type
parameter is actually ignored when removing a column — see the documentation for remove_column
here which specifies that as well.
The docs also indicate why you might want to include it anyway — if your migration is implemented using a change
method instead of up
and down
methods, that parameter indicates what type of column should be added back if you revert the migration.
Hope that helps,
T.J.
P.S. — This mailing list (rubyonrails-core) is intended for discussion about development of the framework itself, not usage of it.
For questions like this one that are not issues with Rails itself, please post to the rubyonrails-talk mailing list (http://groups.google.com/group/rubyonrails-talk ) or somewhere like StackOverflow using the ruby-on-rails
tag (http://stackoverflow.com/questions/tagged/ruby-on-rails ). You can also drop in to the #rubyonrails channel on irc.freenode.net for realtime help. You’ll be more likely to get a quick answer in the future using one of those options.
Hi Schuck,
Thank you for your response, now that makes sense
Sorry about posting on the wrong group, next time i will post on Rals Talk.