0

我在迁移中创建了一个表并给出了一个 column_name 作为:name,但它不是在模式中创建的,那么如何在该现有表中添加列名?

manish@manish:~/workspace/depot$ rake db:migrate
rake aborted!
Multiple migrations have the name CreateUsers
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:608:in `block in migrations'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:600:in `map'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:600:in `migrations'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:701:in `migrations'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:656:in `migrate'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:549:in `up'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/migration.rb:530:in `migrate'
/home/manish/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.1.3/lib/active_record/railties/databases.rake:161:in `block (2 levels) in <top (required)>'
/home/manish/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `eval'
/home/manish/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
4

1 回答 1

0

您可以通过另一个迁移重命名该列。只需创建另一个迁移并添加

def self.up
  rename_column :table_name, :old_column, :new_column
end

并运行迁移。

于 2013-09-19T07:19:53.477 回答