How can i remove a column from table using rails console

好久不见. 提交于 2019-12-03 01:26:49

问题


It is easily possible to remove a column using rails migration.

class SomeClass < ActiveRecord::Migration
  def self.up
    remove_column :table_name, :column_name
  end
end

I want to know if there is any way to remove a column from table using console.


回答1:


You can run the codes in up method directly in rails console:

>> ActiveRecord::Migration.remove_column :table_name, :column_name

If you already have a migration file such as "db/migrate/20130418125100_remove_foo.rb", you can do this:

>> require "db/migrate/20130418125100_remove_foo.rb"
>> RemoveFoo.up

If you just want to do rake db:migrate, try this:

>> ActiveRecord::Migrator.migrate "db/migrate"


来源:https://stackoverflow.com/questions/16074630/how-can-i-remove-a-column-from-table-using-rails-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!