使用rails迁移很容易删除列.
class SomeClass < ActiveRecord::Migration
def self.up
remove_column :table_name, :column_name
end
end
我想知道是否有任何方法可以使用console从表中删除列.
使用rails迁移很容易删除列.
class SomeClass < ActiveRecord::Migration
def self.up
remove_column :table_name, :column_name
end
end
我想知道是否有任何方法可以使用console从表中删除列.
您可以直接在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"