兼容性问题? rake db:migrate - 参数数量错误(1 代表 0)

Posted

技术标签:

【中文标题】兼容性问题? rake db:migrate - 参数数量错误(1 代表 0)【英文标题】:Compatibility issue? rake db:migrate - wrong number of arguments (1 for 0) 【发布时间】:2015-01-25 04:48:08 【问题描述】:

我正在尝试运行一个简单的迁移,但出现此错误。我认为这是某种兼容性错误。我该如何修复它以及如何避免将来出现兼容性问题?


Migration: `class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :nume
      t.string :email
      t.string :localitate

      t.timestamps 
    end
  end
end
___________________

宝石文件

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0.beta4'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.0.beta1'
# Use Uglifier as compressor for javascript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jQuery as the JavaScript library
gem 'jquery-rails', '~> 4.0.0.beta2'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0.0.beta4'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]

___________

错误:

参数数量错误(1 代表 0)C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0 .0/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_ 适配器.rb:271:in initialize' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract_adapter.rb:271:innew' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract_adapter.rb:271:in substitute_at' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/relation.rb:97:inblock 在替代值' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/relation.rb:96:in each' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/relation.rb:96:ineach_with_index' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/relation.rb:96:in substitute_values' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/relation.rb:56:ininsert' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/persistence.rb:521:in _create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/counter_cache.rb:139:in_create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/attribute_methods/dirty.rb:122:in _create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/callbacks.rb:306:inblock in _create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:88:in call' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:88:in_run_callbacks' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:734:in _run_create_callbacks' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/callbacks.rb:306:in_create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/timestamp.rb:57:in _create_record' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/persistence.rb:501:increate_or_update' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/callbacks.rb:302:in block in create_or_update' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:88:incall' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:88:in _run_callbacks' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activesupport-4.2.0.beta4/l ib/active_support/callbacks.rb:734:in_run_save_callbacks' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/callbacks.rb:302:in create_or_update' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/persistence.rb:142:insave!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/validations.rb:42:in save!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/attribute_methods/dirty.rb:29:insave!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:289:in block in save!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:345:inblock in with_transaction_returning_stat 我们' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract/database_statements.rb:211:in tran saction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:218:intransaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:342:in with_transaction_returning_status' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:289:insave!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/persistence.rb:51:in create!' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:1015:inrecord_version_state_after_migrating' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:985:in block in execute_migration_in_transaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:1030:inblock in ddl_transaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract/database_statements.rb:213:in bloc k in transaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract/transaction.rb:188:inwithin_new_t 赎罪 C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/connection_adapters/abstract/database_statements.rb:213:in tran saction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/transactions.rb:218:intransaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:1030:in ddl_transaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:983:inexecute_migration_in_transaction' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:945:in block in migrate' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:941:ineach' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:941:in migrate' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:813:inup' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/migration.rb:791:in migrate' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/tasks/database_tasks.rb:137:inmigrate' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/activerecord-4.2.0.beta4/li b/active_record/railties/databases.rake:44:in block (2 levels) in <top (require d)>' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:240:incall' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:240:in block in execute' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:235:ineach' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:235:in execute' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:179:inblock in invoke_with_call_chain' C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in mon_synchronize' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:172:ininvoke_with_call_chain' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/task.r b:165:in invoke' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:156:ininvoke_task' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:112:in block (2 levels) in top_level' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:112:ineach' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:112:in block in top_level' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:121:inrun_with_threads' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:106:in top_level' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:84:inblock in run' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:182:in standard_exception_handling' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/lib/rake/applic ation.rb:79:inrun' C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rake-10.4.0/bin/rake:33:in <top (required)>' C:/RailsInstaller/Ruby2.0.0/bin/rake:23:inload' C:/RailsInstaller/Ruby2.0.0/bin/rake:23:in `' 任务:TOP => db:migrate

【问题讨论】:

Can't migrate database after scaffold. Section 2.2 Ruby on Rails Tutorial Michael Hartl. 的可能重复项 我没有使用脚手架 请仔细阅读链接,这是一个rails错误,我今天强制关闭3个这样的问题。 谢谢。我很困惑。我什至没有“arel”宝石。 【参考方案1】:

答案在这里:Can't migrate database after scaffold. Section 2.2 Ruby on Rails Tutorial Michael Hartl

您需要按照那里的说明安装 arel gem。

【讨论】:

以上是关于兼容性问题? rake db:migrate - 参数数量错误(1 代表 0)的主要内容,如果未能解决你的问题,请参考以下文章

markdown rake db:reset,rake db:migrate:resetの违い

如何运行 db:migrate 从另一个带参数的 rake 任务?

rake db:migrate不执行任何操作

如何使用 rake db:migrate 仅回滚一步

在 Heroku 上执行 rake db:migrate 时出错

使用 rake db:migrate 迁移数据不会改变它