设计可确认的迁移错误

时间:2018-08-16 02:15:40

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

我是刚接触Ruby的新手,并且很难理解我在这里看到的错误,并且在搜索时找不到它。

我正在将Devise添加到我的应用程序中,并希望使其可确认。因此,我将Devise添加到了gem文件中,进行了捆绑安装,将行添加到了development.rb中,做了根“ home#home”,并在布局中添加了通知/警报。没问题。

model / user.rb

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :validatable
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.inet     :current_sign_in_ip
      # t.inet     :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 db:migrate

我得到了错误

== 20180816012427 DeviseCreateStudents: migrating =============================
-- create_table(:users)
   -> 0.0021s
-- add_index(:users, :email, {:unique=>true})
   -> 0.0013s
-- add_index(:users, :reset_password_token, {:unique=>true})
   -> 0.0013s
-- add_index(:users, :confirmation_token, {:unique=>true})
   -> 0.0016s
-- add_index(:users, :unlock_token, {:unique=>true})
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table users has no column named unlock_token: CREATE UNIQUE INDEX "index_users_on_unlock_token" ON "users" ("unlock_token")

我仍在学习不同的错误意味着什么,但是无法找到这意味着什么。感谢您的关注。

1 个答案:

答案 0 :(得分:0)

第一个评论是正确的。我也不怎么想索引。