0

这真的很奇怪。我已经使用了数百次 Devise 并且从未收到此错误。这是我的模型:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

这是架构:

  create_table "users", force: :cascade do |t|
    t.string   "email",                  limit: 255, default: "", null: false
    t.string   "encrypted_password",     limit: 255, default: "", null: false
    t.string   "reset_password_token",   limit: 255
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    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",     limit: 255
    t.string   "last_sign_in_ip",        limit: 255
    t.datetime "created_at",                                      null: false
    t.datetime "updated_at",                                      null: false
    t.string   "first_name",             limit: 255
    t.string   "last_name",              limit: 255
    t.string   "type",                   limit: 255
    t.integer  "patient_id"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["patient_id"], name: "index_users_on_patient_id"
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

我进入 rails 控制台并输入:

u = User.create(email:'fsdfdas@fdf.com', password: 'password', password_confirmation: 'password')

不知何故我得到了这个错误:

2.2.0 :001 > u = User.create(email:'fsdfdas@fdf.com', password: 'password', password_confirmation: 'password')
   (0.1ms)  begin transaction
  User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = 'fsdfdas@fdf.com' LIMIT 1
  SQL (0.1ms)  INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)  [["email", "fsdfdas@fdf.com"], [nil, nil], ["encrypted_password", "$2a$11$XAjcHN39soOIk6xh9CckmOFc7osxpsHfwCX/ASsLXwsRac/UItIli"], ["created_at", "2016-04-06 16:49:47.400937"], ["updated_at", "2016-04-06 16:49:47.400937"]]
SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)
   (0.0ms)  rollback transaction
ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)

怎么了?我已经安装了devise_token_auth gem,但还没有实现它,所以我不知道它能做什么。

4

1 回答 1

1

这最终成为一个 gem 版本控制问题。我在 gemfile 中有这样的导轨:

gem 'rails', '4.2.0'

将其替换为:

gem 'rails'

并运行bundle update,问题停止了。

于 2016-04-06T17:49:13.670 回答