【问题标题】:rails 4 devise error: SQLite3::SQLException: table users has no column named passwordrails 4 设计错误:SQLite3::SQLException:表用户没有名为密码的列
【发布时间】:2016-04-06 17:02:10
【问题描述】:

这真的很奇怪。我已经使用了数百次 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,但还没有实现它,所以我不知道它可以做什么。

【问题讨论】:

  • 设计应该在其:validatable 模块中为passwordpassword_confirmation 设置虚拟属性。您使用的是什么设计版本?

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


【解决方案1】:

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

gem 'rails', '4.2.0'

替换为:

gem 'rails'

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

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    相关资源
    最近更新 更多