使用Rails迁移很容易删除列。
class SomeClass < ActiveRecord::Migration
def self.up
remove_column :table_name, :column_name
end
end
我想知道是否有办法在控制台中移除表格中的某一列。
使用Rails迁移很容易删除列。
class SomeClass < ActiveRecord::Migration
def self.up
remove_column :table_name, :column_name
end
end
我想知道是否有办法在控制台中移除表格中的某一列。
您可以直接在rails console
中运行up
方法中的代码:
>> ActiveRecord::Migration.remove_column :table_name, :column_name
db/migrate/20130418125100_remove_foo.rb
",您可以执行以下操作:>> require "db/migrate/20130418125100_remove_foo.rb"
>> RemoveFoo.up
如果你只想运行rake db:migrate
,尝试这样做:
>> ActiveRecord::Migrator.migrate "db/migrate"
ActiveRecord::Migration.remove_column :table_name, :column_name
可以翻译为“ActiveRecord::Migration.remove_column :表名,列名”,而“This worked great!!”可以翻译为“这很棒!” - Jordan