Rake不会回滚迁移,错误的参数数量(1为0)

时间:2016-02-22 07:45:30

标签: mysql ruby-on-rails ruby-on-rails-4

我有一个包含多个表的项目,仍处于早期开发阶段。我需要对迁移进行一些更改,并希望回滚以正确执行此操作。这些是微小的更改,我更愿意直接编辑迁移,而不是创建更改迁移。

当我运行x += y.todense()时,我收到以下异常:

rake db:rollback

这个数据库是全新的 - 我刚刚完成wrong number of arguments (1 for 0)/Users/mmo/.rvm/gems/ruby-2.2.4/gems/activerecord-4.2.5/lib/active_record/migration.rb:492:in `initialize'

rake db:drop db:migrate显示了这一点:

rake db:migrate:status

Gemfile看起来像这样:

 Status   Migration ID    Migration Name
--------------------------------------------------
   up     20151229013054  Create courses
   up     20151229013055  Create races
   up     20151229013326  Create events
   up     20151229013400  Create countries
   up     20151229013424  Create participants
   up     20151229013616  Create efforts
   up     20151229013622  Create locations
   up     20151229013757  Create splits
   up     20151229013938  Create split times
   up     20151229014302  Create users
   up     20160129060100  Create interests
   up     20160131195951  Create ownerships

任何想法都会受到最高的赞赏。

编辑:这是--trace结果:

source 'https://rubygems.org'
ruby '2.2.4'
gem 'rails', '4.2.5'
gem 'sqlite3'
gem 'responders', '~> 2.0'
gem 'mysql2', '~> 0.3.18'
gem 'sass-rails', '~> 5.0.4'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'kaminari'
gem 'turbolinks'
group :development, :test do
  gem 'byebug'
end
group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end
gem 'bootstrap-sass'
gem 'high_voltage'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'devise'
gem 'pundit'
gem 'rails_apps_pages'
gem 'therubyracer', :platform=>:ruby
gem 'ar-audit-tracer'
gem 'oj'
gem 'alchemist'
group :development do
  gem 'better_errors'
  gem 'foreman'
  gem 'rails_layout'
end
group :development, :test do
  gem 'pry-rails'
  gem 'pry-rescue'
  gem 'rubocop', '~> 0.36'
  gem 'rspec', '~> 3.4'
  gem 'rspec-rails', '~> 3.0'
end

最后一件事:我尝试了$rake db:migrate --trace ** Invoke db:_dump (first_time) ** Execute db:_dump ** Invoke db:schema:dump (first_time) ** Invoke environment ** Invoke db:load_config ** Execute db:schema:dump $rake db:rollback --trace ** Invoke db:rollback (first_time) ** Invoke environment (first_time) ** Execute environment ** Invoke db:load_config (first_time) ** Execute db:load_config ** Execute db:rollback ,然后只运行了第一次迁移(rake db:drop db:create)。即便如此,我也无法回滚单一迁移。我得到了同样的错误。

3 个答案:

答案 0 :(得分:0)

您已删除数据库并已将其迁移。你应该再创一个。

rake db:drop

rake db:create db:migrate

Please go through this answer

migration.rb中的第492行,

 <tt>ActiveRecord::Migration::CommandRecorder</tt>.

所以你再次创建数据库。

答案 1 :(得分:0)

试一试 连续明智:

rake db:drop :- drops the database for the current env
rake db:create :- creates the database for the current env
rake db:setup :- runs db:schema:load, db:seed

答案 2 :(得分:0)

我正在使用'ar-audit-tracer'gem来自动记录我的记录。原来这个gem创建了rake db:rollback的问题。当我评论出宝石时,我可以回滚得很好。不确定这是一般问题还是仅针对我的情况。