rake db:migrate抛出的参数数量错误

时间:2016-06-19 23:40:52

标签: ruby-on-rails ruby migration bundler

我正在尝试运行迁移,但我一直收到错误消息。

我们尝试删除迁移内容,只留下以下内容:

class CreateUsers < ActiveRecord::Migration
  def change      
  end
end

仍会导致错误消息:

$ be rake db:migrate
== 20160619232005 CreateUsers: migrating ======================================
-- create_table(:users)    -> 0.0042s
== 20160619232005 CreateUsers: migrated (0.0043s) =============================

rake aborted! 
  StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 1, expected 0) 
/home/ericmarche/.rbenv/versions/2.3.1/bin/bundle:22:in `load' 
/home/ericmarche/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>' ArgumentError: wrong number of arguments (given 1, expected 0) 
/home/ericmarche/.rbenv/versions/2.3.1/bin/bundle:22:in `load' 
/home/ericmarche/.rbenv/versions/2.3.1/bin/bundle:22:in `<main>' Tasks: TOP => db:migrate (See full trace by running task with --trace)

3 个答案:

答案 0 :(得分:0)

您可以使用以下方法删除整个内容:

class Student < User
  has_and_belongs_to_many :teachers, join_table: :students_teachers
end

然后重新创建它,然后尝试重新迁移:

rails d model user

OR

您可以转到rails控制台并删除users表并重新迁移

rails g model user
rake db:migrate

然后尝试重新移植表

答案 1 :(得分:0)

您是否尝试创建新项目并运行

bundle exec rake db:migrate

答案 2 :(得分:-1)

您使用be rake db:migrate运行迁移的原因 be的意思是什么。

在项目目录中运行迁移而不使用be

rake db:migrate

例:

$cd workspace/project

workspace/project$ rake db:migrate