Rake db:在使用mysql db的设备上迁移失败

时间:2015-11-01 04:02:41

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

所以我遵循基于Devise read.me入门的流程。这是我做的过程

创建了我的rails项目 添加了宝石'设计' rake db:create rails generate devise:install 为路由添加了home #index 将action_mailer_deafult_url_options添加到development.rb rails生成设备用户 rake db:当我运行rake db:migrate时迁移,它失败并给我这个错误报告

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

super: no superclass method sanitize_for_mass_assignment' for #<ActiveRecord::SchemaMigration version: nil> NoMethodError: super: no superclass methodsanitize_for_mass_assignment' for #

user.rb

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :registerable

end

迁移文件

class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

      ## Confirmable
      # t.string   :confirmation_token
      # t.datetime :confirmed_at
      # t.datetime :confirmation_sent_at
      # t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
      # t.string   :unlock_token # Only if unlock strategy is :email or :both
      # t.datetime :locked_at


      t.timestamps null: false
    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true
    # add_index :users, :confirmation_token,   unique: true
    # add_index :users, :unlock_token,         unique: true
  end
end

有谁知道发生这种情况的原因

我正在使用rails - 4.2.3和Devise 3.5.2

1 个答案:

答案 0 :(得分:0)

如果您遇到这个问题并且已经安装了gem&#39; strong_parameters&#39;请删除它,因为它已经在Rails 4.0中添加到ActiveModel和ActiveController中。文档让我困惑,所以我添加了宝石,这导致我的错误。