问题描述
我正在研究Hartl rails on rails教程(第2.2节),并且在迁移数据库时遇到了麻烦.一切似乎都正常,然后我运行了rails generate scaffold User name:string email:string
之后,我尝试运行bundle exec rake db:migrate并得到以下错误消息:
I'm working through the Hartl ruby on rails tutorial (section 2.2), and I'm having trouble migrating the database. Everything seemed to be working, and then I ran rails generate scaffold User name:string email:string
Afterwards I tried to run bundle exec rake db:migrate and got the below error message:
$ bundle exec rake db:migrate
== 20141125234257 CreateUsers: migrating ======================================
-- create_table(:users)
-> 0.0079s
== 20141125234257 CreateUsers: migrated (0.0080s) =============================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 0)/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `new'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `substitute_at'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97:in `block in substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each_with_index'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56:in `insert'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:521:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/counter_cache.rb:139:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:122:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `block in _create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/timestamp.rb:57:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:501:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:142:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/validations.rb:42:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `block in save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:51:in `create!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1015:in `record_version_state_after_migrating'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:985:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
ArgumentError: wrong number of arguments (1 for 0)
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `new'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `substitute_at'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:97:in `block in substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `each_with_index'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:96:in `substitute_values'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/relation.rb:56:in `insert'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:521:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/counter_cache.rb:139:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:122:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `block in _create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:306:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/timestamp.rb:57:in `_create_record'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:501:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `block in create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `call'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activesupport-4.2.0.beta4/lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/callbacks.rb:302:in `create_or_update'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:142:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/validations.rb:42:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `block in save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:289:in `save!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:51:in `create!'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1015:in `record_version_state_after_migrating'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:985:in `block in execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `block in ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:1030:in `ddl_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:983:in `execute_migration_in_transaction'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:945:in `block in migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `each'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:941:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:813:in `up'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/migration.rb:791:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我尝试返回到较早的提交,然后再次运行所有内容,但收到相同的错误消息.我是否还应该添加其他文件来帮助解决此问题?
I've tried going back to an earlier commit and running everything again but I get the same error message. Are there any more files that I should add that can help with this?
推荐答案
我也遇到了这个问题.这是由于ActiveRecord 4.2.0.beta4将参数传递给Arel::Nodes::BindParam.new
. Arel 6.0.0于今天发布.在此版本中,BindParam
在其初始化器中不接受任何参数.
I just ran into this as well. This is due to ActiveRecord 4.2.0.beta4 passing a parameter to Arel::Nodes::BindParam.new
. Arel 6.0.0 was just released today. In this version, BindParam
does not accept any parameters in it's initalizer.
ActiveRecord已在master
分支上解决此问题.在beta5发布之前,您需要将Gemfile
锁定为gem 'arel', '6.0.0.beta2'
.
ActiveRecord has already fixed this on the master
branch. Until beta5 is released you'll need to lock your Gemfile
to gem 'arel', '6.0.0.beta2'
.
这篇关于脚手架后无法迁移数据库. 2.2节Ruby on Rails教程Michael Hartl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!