简体   繁体   English

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

[英]Rake won't rollback migrations, wrong number of arguments (1 for 0)

I have a project with several tables, still in early development stage. 我有一个带有多个表的项目,该项目仍处于早期开发阶段。 I need to make some changes to the migrations and would like to rollback to do it properly. 我需要对迁移进行一些更改,并希望回滚以正确执行。 These are minor changes and I would prefer to edit the migrations directly rather than create change migrations. 这些都是较小的更改,我希望直接编辑迁移,而不是创建更改迁移。

When I run rake db:rollback I get the following exception: 当我运行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'

This database is brand new--I've just done rake db:drop db:migrate . 该数据库是全新的-我刚刚完成了rake db:drop db:migrate

And rake db:migrate:status shows this: rake db:migrate:status显示如下:

 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

Gemfile looks like this: Gemfile看起来像这样:

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

Any ideas would be most appreciated. 任何想法将不胜感激。

EDIT: Here are the --trace results: 编辑:这是--trace结果:

$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

One last thing: I tried rake db:drop db:create and then just ran the first migration ( rake db:migrate VERSION=20151229013054 ). 最后一件事:我尝试了rake db:drop db:create ,然后运行了第一个迁移( rake db:migrate VERSION=20151229013054 )。 Even then I couldn't rollback that single migration. 即使那样,我也无法回滚该单个迁移。 I get the same error. 我犯了同样的错误。

You have dropped the database and migrated it. 您已删除数据库并进行了迁移。 You should create one again. 您应该再次创建一个。

rake db:drop

rake db:create db:migrate

Please go through this answer 请通过这个答案

Line number 492 in migration.rb, migration.rb中的第492行,

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

So you shld create the db again. 因此,您将再次创建数据库。

Give them a try serial wise: 给他们一个连续的尝试:

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

I am using the 'ar-audit-tracer' gem for automatic user-stamping of my records. 我正在使用“ ar-audit-tracer” gem对记录进行自动用户标记。 Turns out this gem creates a problem with rake db:rollback. 事实证明,这个gem造成了rake db:rollback的问题。 When I comment out the gem, I can rollback just fine. 当我注释掉该宝石时,我可以回滚。 Not sure if this is a general problem or just specific to my case. 不知道这是普遍问题还是仅针对我的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM