rails 4设计错误:SQLite3 :: SQLException:表用户没有名为password的列

时间:2016-04-06 17:02:10

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

这真的很奇怪。我已经使用了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但尚未实现它,所以我不知道可以做些什么。

1 个答案:

答案 0 :(得分:1)

这最终成为宝石版本问题。我在gemfile中有像这样的轨道:

gem 'rails', '4.2.0'

将其替换为:

gem 'rails'

并且正在运行bundle update,问题就停止了。