Rake 迁移错误 "wrong number of arguments"
Rake Migrate error "wrong number of arguments"
我正在尝试向我拥有的模型添加列(线索)。我在网上看到这与我的迁移文件有关。
这是我的迁移文件:
class Addboolstoclue < ActiveRecord::Migration
def self.up
add_column :clue do |t|
t.boolean :clue1
t.boolean :clue2
t.boolean :clue3
t.boolean :clue4
t.boolean :clue5
t.boolean :clue6
t.boolean :clue7
t.boolean :clue8
t.boolean :clue9
t.boolean :clue10
t.boolean :clue11
t.boolean :clue12
t.boolean :clue13
t.boolean :clue14
t.boolean :clue15
t.boolean :done
t.string :user_id
end
end
end
当我 运行 迁移时出现此错误,我的终端:
rake db:migrate
== 20150418012429 Addboolstoclue: migrating ===================================
-- add_column(:clue)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 3..4)/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:452:in `add_column'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `say_with_time'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:641:in `method_missing'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:406:in `method_missing'
/Users/coleschiffer/Code/rp/protected-beyond-7706/db/migrate/20150418012429_addboolstoclue.rb:3:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:558:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:598:in `exec_migration'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:578:in `block in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:577:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:752:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/transactions.rb:208:in `transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `ddl_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:953:in `block in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `each'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
感谢您的帮助!
add_column一般是一次一列,不是分块:
add_column :clue, :clue1, :boolean
add_column :clue, :clue2, :boolean
...
您将希望在 self.change 方法中执行此操作,而不是编写 up 和 down 方法。 rails 指南的这一部分对其进行了更多讨论:
http://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration
尝试一次添加多个列时,请尝试 change_table 而不是 add_column
喜欢 :
class Addboolstoclue < ActiveRecord::Migration
def change
change_table :clue do |t|
t.boolean :clue1
t.boolean :clue2
t.boolean :clue3
t.boolean :clue4
t.boolean :clue5
t.boolean :clue6
t.boolean :clue7
t.boolean :clue8
t.boolean :clue9
t.boolean :clue10
t.boolean :clue11
t.boolean :clue12
t.boolean :clue13
t.boolean :clue14
t.boolean :clue15
t.boolean :done
t.string :user_id
end
end
end
我正在尝试向我拥有的模型添加列(线索)。我在网上看到这与我的迁移文件有关。 这是我的迁移文件:
class Addboolstoclue < ActiveRecord::Migration
def self.up
add_column :clue do |t|
t.boolean :clue1
t.boolean :clue2
t.boolean :clue3
t.boolean :clue4
t.boolean :clue5
t.boolean :clue6
t.boolean :clue7
t.boolean :clue8
t.boolean :clue9
t.boolean :clue10
t.boolean :clue11
t.boolean :clue12
t.boolean :clue13
t.boolean :clue14
t.boolean :clue15
t.boolean :done
t.string :user_id
end
end
end
当我 运行 迁移时出现此错误,我的终端:
rake db:migrate
== 20150418012429 Addboolstoclue: migrating ===================================
-- add_column(:clue)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 3..4)/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:452:in `add_column'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:649:in `block in method_missing'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `block in say_with_time'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:621:in `say_with_time'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:641:in `method_missing'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:406:in `method_missing'
/Users/coleschiffer/Code/rp/protected-beyond-7706/db/migrate/20150418012429_addboolstoclue.rb:3:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:558:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:598:in `exec_migration'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:578:in `block in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:577:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:752:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/transactions.rb:208:in `transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:1038:in `ddl_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:953:in `block in migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `each'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:949:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:807:in `up'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/migration.rb:785:in `migrate'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/gems/activerecord-4.1.0/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/Users/coleschiffer/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
感谢您的帮助!
add_column一般是一次一列,不是分块:
add_column :clue, :clue1, :boolean
add_column :clue, :clue2, :boolean
...
您将希望在 self.change 方法中执行此操作,而不是编写 up 和 down 方法。 rails 指南的这一部分对其进行了更多讨论:
http://guides.rubyonrails.org/active_record_migrations.html#creating-a-standalone-migration
尝试一次添加多个列时,请尝试 change_table 而不是 add_column 喜欢 :
class Addboolstoclue < ActiveRecord::Migration
def change
change_table :clue do |t|
t.boolean :clue1
t.boolean :clue2
t.boolean :clue3
t.boolean :clue4
t.boolean :clue5
t.boolean :clue6
t.boolean :clue7
t.boolean :clue8
t.boolean :clue9
t.boolean :clue10
t.boolean :clue11
t.boolean :clue12
t.boolean :clue13
t.boolean :clue14
t.boolean :clue15
t.boolean :done
t.string :user_id
end
end
end